home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / text / show / muchmore45.lha / MuchMore / Src / MuchMore.mod next >
Text File  |  1994-07-01  |  93KB  |  2,822 lines

  1. (*---------------------------------------------------------------------------
  2. :Program.    MuchMore.mod
  3. :Author.     Fridtjof Siebert
  4. :Address.    Nobileweg 67, D-70439 Stuttgart, Germany
  5. :Shortcut.   [fbs]
  6. :Copyright.  Freeware
  7. :Language.   Oberon-2
  8. :Translator. Amiga Oberon Compiler v3.10
  9. :History.   V1.0 summer-88: First very slow internal version             [fbs]
  10. :History.   V1.1 24-Sep-88: First published version                      [fbs]
  11. :History.   V1.2 26-Nov-88: Now displays Filelength & Percentage         [fbs]
  12. :History.        27-Nov-88: Mouse can be used instead of Space/BackSpace [fbs]
  13. :History.   V1.3 29-Apr-89: Strong increase in speed, removed WarpText   [fbs]
  14. :History.        29-Apr-89: Now supports Numeric Keys (Home,PgUp etc.)   [fbs]
  15. :History.        29-Apr-89: Now opens Screen as big as gfx.normalDisplay [fbs]
  16. :History.   V1.4 29/30-Apr-89: Asynchronus loading/displaying. Very nice [fbs]
  17. :History.        30-Apr-89, 00:33: Removed bugs in Filelength & L-Command[fbs]
  18. :History.        30-Apr-89, 02:21: Added Find-Command                    [fbs]
  19. :History.        30-Apr-89, 10:30: Scrolling stops when window inactive  [fbs]
  20. :History.        01-May-89: Allocates no more unneeded memory for text   [fbs]
  21. :History.        07-May-89: Allocates even less memory now               [fbs]
  22. :History.        14-May-89: Removed deadlock-bug with Find-Window        [fbs]
  23. :History.   V1.5 25-May-89: Added print feature                          [fbs]
  24. :History.        25-May-89: Removed all imports (apart from Arts)        [fbs]
  25. :History.        26-May-89: inspired by J. Kupfer, I added nk 5 to quit  [fbs]
  26. :History.        26-May-89: Now handle BS correctly                      [fbs]
  27. :History.   V1.6 02-Jul-89: Now supports several fontstyles and colors   [fbs]
  28. :History.   V1.7 03-Jul-89: Is again as fast as it was with 2 colors     [fbs]
  29. :History.        03-Jul-89: Now no more crashes when quitting while print[fbs]
  30. :History.        07-Jul-89: removed bug with texts of length 0           [fbs]
  31. :History.   V1.8 10-Jul-89: small bug in find-command removed            [fbs]
  32. :History.        10-Jul-89: now found strings are highlighted            [fbs]
  33. :History.        14-Jul-89: nk0 to display fileinfo                      [fbs]
  34. :History.   V2.0 06-Aug-89: Ported this to OBERON                        [fbs]
  35. :History.        06-Aug-89: Added ARP-FileRequester                      [fbs]
  36. :History.        07-Aug-89: Added L - (load new file) Command            [fbs]
  37. :History.   V2.1 03-Sep-89: no more gurus if an r/w error occures        [fbs]
  38. :History.        03-Sep-89: MM used to execute CSI-Codes backwards. fixed[fbs]
  39. :History.        03-Sep-89: ping / pong with Shift+Fn / Fn               [fbs]
  40. :History.        03-Sep-89: new command: goto                            [fbs]
  41. :History.   V2.2 05-Sep-89: will run with any keymapping now             [fbs]
  42. :History.   V2.3 17-Sep-89: New command: sleep & Pop-Up feature          [fbs]
  43. :History.        17-Sep-89: "MuchMore -s" will go to sleep immediately   [fbs]
  44. :History.        17-Sep-89: Interprets <CSI>m as <CSI>0m now             [fbs]
  45. :History.   V2.4 17-Sep-89: New command: write block "w"                 [fbs]
  46. :History.        17-Sep-89: rewritten argument parser to allow quotes    [fbs]
  47. :History.   V2.5 18-Sep-89: now uses the 8x8 font set with SetFont       [fbs]
  48. :History.        19-Sep-89: no more scatters memory. Allocates 4K Chunks [fbs]
  49. :History.   V2.6 26-Jun-90: Made MuchMore reentrant                      [fbs]
  50. :History.        26-Jun-90: Opens 1-Plane Screen if memory is rare       [fbs]
  51. :History.        26-Jun-90: Asynchronus fast scrolling with Ctrl-Up/Down [fbs]
  52. :History.        26-Jun-90: Now supports interlaced screens              [fbs]
  53. :History.        08-Aug-90: CLI-Option '-l' to toggle interlaced mode    [fbs]
  54. :History.   V2.7 09-Aug-90: no more RethinkDisplay()s,looks good with 2.0[fbs]
  55. :History.        10-Aug-90: Supports Kick2.0 ASL-FileRequester           [fbs]
  56. :History.   V2.8 26-Dez-90: Leaves space between lines on interl. scrns  [fbs]
  57. :History.   V3.0 04-Jul-91: Supports any non-proportional font now       [fbs]
  58. :History.        04-Jul-91: no more supports '-s' (sleep),was rarely used[fbs]
  59. :History.        04-Jul-91: new Options -f<font> and -s<size> for font   [fbs]
  60. :History.        09-Nov-91: Find works w/ dmouse(window may get inactive)[fbs]
  61. :History.   V3.1 04-Sep-92: Uses Screenmode of Workbench screen          [fbs]
  62. :History.   V3.2 02-Nov-92: Supports non-scrollable screens              [fbs]
  63. :History.        02-Nov-92: Complete redraw doesn't scroll anymore       [fbs]
  64. :History. V3.2.1 24-Dec-92: XPK Support                             (C.Stiens)
  65. :History.        24-Dec-92: New option -p for Password              (C.Stiens)
  66. :History.        24-Dec-92: New option -e for Extra Spacing         (C.Stiens)
  67. :History.        24-Dec-92: New option -c for Screen Colors         (C.Stiens)
  68. :History.        24-Dec-92: Tooltypes                               (C.Stiens)
  69. :History. V3.2.2 08-Jan-93: Doesn't use MyMakeScreen() no more      (C.Stiens)
  70. :History. V3.2.3 08-Feb-93: Now closes Console Device               (C.Stiens)
  71. :History.        08-Feb-93: Non-Scroll Mode didn't work always      (C.Stiens)
  72. :History.        10-Feb-93: ScreenMode Requester                    (C.Stiens)
  73. :History.        10-Feb-93: New Option -s for Scroll Mode           (C.Stiens)
  74. :History.        10-Feb-93: Busy Pointer                            (C.Stiens)
  75. :History.        14-Feb-93: Now evals Tooltypes also on CLI start   (C.Stiens)
  76. :History. V3.2.4 15-Feb-93: Clears Idcmp while Busy                 (C.Stiens)
  77. :History.        15-Feb-93: Bugs in GetString fixed                 (C.Stiens)
  78. :History.        19-Feb-93: More Scrollmodes                        (C.Stiens)
  79. :History.        20-Feb-93: Bug in Type() fixed                     (C.Stiens)
  80. :History. V3.2.5 08-Mar-93: Asynch Scrolling changed                (C.Stiens)
  81. :History.        08-Mar-93: New Option -t for Taskpri               (C.Stiens)
  82. :History.        10-Mar-93: Now uses Dos.ReadArgs if KS 2.04        (C.Stiens)
  83. :History. V3.2.6 19-Mar-93: scrollmode 3 now also scrolls soft      (C.Stiens)
  84. :History.        19-Mar-93: New Option -o for one plane             (C.Stiens)
  85. :History.        19-Mar-93: New Option -a for tab width             (C.Stiens)
  86. :History.        19-Mar-93: Removed QText                           (C.Stiens)
  87. :History.        21-Mar-93: Opens screen with full overscan width   (C.Stiens)
  88. :History.        22-Mar-93: Filename can be on any pos at KS1.3     (C.Stiens)
  89. :History.        27-Mar-93: New Option N=NOOSCAN                    (C.Stiens)
  90. :History. V3.2.7 07-Apr-93: Dont pokes to bitmap no more            (C.Stiens)
  91. :History. V3.2.8 12-Apr-93: New Option B=PLANES                     (C.Stiens)
  92. :History. V3.2.9 12-May-93: Implemented V36 ANSI Codes              (C.Stiens)
  93. :History. 3.2.10 16-May-93: Locale Support                          (C.Stiens)
  94. :History.        16-May-93: DispMode-Requester font-sensitive       (C.Stiens)
  95. :History.   V3.3 21-Jun-93: Code optimised                          (C.Stiens)
  96. :History.        25-Jun-93: Safe quit                               (C.Stiens)
  97. :History.   V3.4 29-Jun-93: Clipboard support                       (C.Stiens)
  98. :History.        29-Jun-93: took version number out of catalog      (C.Stiens)
  99. :History.   V3.5 31-Jul-93: case sensitive search, Boyer-Moore Alg. (C.Stiens)
  100. :History.   V3.6 15-Aug-93: Page up/down with softscroll reimpl.    (C.Stiens)
  101. :History.        16-Aug-93: Flash at EOF/BOF                        (C.Stiens)
  102. :History.   V3.7 28-Oct-93: New option E=EDITOR                     (C.Stiens)
  103. :History.        21-Nov-93: MM was not 100% pure (BusyPointer)      (C.Stiens)
  104. :History.        21-Nov-93: Password has to be entered in stringgad (C.Stiens)
  105. :History.   V4.0 07-Dec-93: MM can run in a WB Window               (C.Stiens)
  106. :History.        07-Dec-93: Options WINDOW, LEFT, TOP, WIDTH, HEIGHT(C.Stiens)
  107. :History.        07-Dec-93: Kick 1.3 is no more supported           (C.Stiens)
  108. :History.        07-Dec-93: Removed Options SCROLLMODE and NOOSCAN  (C.Stiens)
  109. :History.   V4.1 05-Jan-94: Prefs BusyPointer, set rp.mask or MaxPen(C.Stiens)
  110. :History.        10-Jan-94: Pipe Support, new option PUBSCREEN      (C.Stiens)
  111. :History.        12-Jan-94: Option SCROLLMODE reintroduced          (C.Stiens)
  112. :History.        12-Jan-94: New Option I=INTERLEAVED                (C.Stiens)
  113. :History.   V4.2 29-Jan-94: Zoom Gadget (v39)                       (C.Stiens)
  114. :History.        29-Jan-94: Better test for Pipe                    (C.Stiens)
  115. :History.        30-Jan-94: Icon is found if MM is started w/path   (C.Stiens)
  116. :History.        31-Jan-94: New option FASTQUIT                     (C.Stiens)
  117. :History.        31-Jan-94: ShowTask allocates his signals now      (C.Stiens)
  118. :History.   V4.3 06-Mar-94: Change rp.mask only if necessary        (C.Stiens)
  119. :History.        16-Mar-94: New options: FRWIDTH, FRHEIGHT          (C.Stiens)
  120. :History.        20-Mar-94: Hide password when entering             (C.Stiens)
  121. :History.   V4.4 17-Jun-94: Bug in task sync fixed                  (C.Stiens)
  122. :History.        17-Jun-94: Uses ASL ScreenMode Requester now       (C.Stiens)
  123. :History.   V4.5 30-Jun-94: Bug w/ SetFont() fixed                  (C.Stiens)
  124. :Contents.   A Soft-Scrolling ASCII-File Viewer.
  125. :Remark.     Compile: 'Oberon -svbcrntzdma MuchMore' for short code
  126. :Remark.     Compile: 'Oberon -dma MuchMore' for safe code
  127. :Remark.     Link:    'OLink -dma MuchMore'
  128. ---------------------------------------------------------------------------*)
  129.  
  130. MODULE MuchMore; (* $StackChk- *)
  131.  
  132. IMPORT loc:= Locale,
  133.        ip := IFFParse,
  134.        u  := Utility,
  135.        con:= Console,
  136.        str:= Strings,
  137.        ie := InputEvent,
  138.        I  := Intuition,
  139.        g  := Graphics,
  140.        d  := Dos,
  141.        e  := Exec,
  142.        ol := OberonLib,
  143. (* $IF quiet *) NoRequesters, (* $END *)
  144.        SYS:= SYSTEM;
  145.  
  146.  
  147. CONST
  148.   MuchText = "MuchMore 4.5 © 1988-94 AMOK\o$VER: muchmore 4.5 (30.6.94)";
  149.   Version = "v4.5";
  150.  
  151.   MSGOOM        = 0;
  152.   MSGCOS        = 1;
  153.   MSGCOW        = 2;
  154.   MSGCOF        = 3;
  155.   MSGRWERR      = 4;
  156.   MSGRETRYABORT = 5;
  157.   MSGEMPTY      = 6;
  158.   MSGSAVE       = 7;
  159.   MSGUSE        = 8;
  160.   MSGCANCEL     = 9;
  161.   MSGOK         = 10;
  162.   MSGCHOOSESM   = 11;
  163.   MSGINFOFMT    = 12;
  164.   MSGH1         = 13;
  165.   MSGH2         = 14;
  166.   MSGH3         = 15;
  167.   MSGH4         = 16;
  168.   MSGH5         = 17;
  169.   MSGH6         = 18;
  170.   MSGH7         = 19;
  171.   MSGH8         = 20;
  172.   MSGH9         = 21;
  173.   MSGH10        = 22;
  174.   MSGH11        = 23;
  175.   MSGH12        = 24;
  176.   MSGH13        = 25;
  177.   MSGH14        = 26;
  178.   MSGH15        = 27;
  179.   MSGH16        = 28;
  180.   MSGH17        = 29;
  181.   MSGH18        = 30;
  182.   MSGH19        = 31;
  183.   MSGH20        = 32;
  184.   MSGH21        = 33;
  185.   MSGH22        = 34;
  186.   MSGH23        = 35;
  187.   MSGH24        = 36;
  188.  
  189.  
  190.   TYPE
  191.     MSGTYPE = ARRAY 37 OF e.LSTRPTR;
  192.  
  193.   CONST
  194.  
  195.     MSGS = MSGTYPE(
  196.       SYS.ADR( "Out of memory"      ),
  197.       SYS.ADR( "Can't open screen"  ),
  198.       SYS.ADR( "Can't open window"  ),
  199.       SYS.ADR( "Can't open file"    ),
  200.       SYS.ADR( "Read/Write Error"   ),
  201.       SYS.ADR( "Retry|Abort"        ),
  202.       SYS.ADR( "File empty"         ),
  203.       SYS.ADR( "Save"               ),
  204.       SYS.ADR( "Use"                ),
  205.       SYS.ADR( "Cancel"             ),
  206.       SYS.ADR( " OK "               ),
  207.       SYS.ADR( "Choose Screen Mode:"),
  208.       SYS.ADR( " File: %-30.30s %ld%% (%ld of %ld Bytes) %ld Lines"),
  209.       SYS.ADR( "\x13                \x15  MuchMore %s Commands:  "),
  210.       SYS.ADR( " \x0dSpace\x05,\x0d LMB\x05:         Start / Stop scrolling, Quit at end of file"),
  211.       SYS.ADR( " \x0dBackSpace\x05,\x0d RMB\x05:     Start / Stop scrolling backwards"),
  212.       SYS.ADR( " \x0dUp\x05/\x0dDown\x05:            Move one line \x0dup\x05 or \x0ddown\x05"),
  213.       SYS.ADR( " \x0dShift \x05+\x0d Up\x05/\x0dDn\x05:      Start / Stop quick scrolling \x0dup\x05 or \x0ddown\x05"),
  214.       SYS.ADR( " \x0dControl\x05:            Increase scroll speed"),
  215.       SYS.ADR( " \x0dAlt\x05+\x0dUp\x05/\x0dDn\x05,\x0d PgUp\x05/\x0dDn\x05: Move one page \x0dup\x05 or \x0ddown\x05"),
  216.       SYS.ADR( " \x0dT\x05,\x0d Home \x05/\x0d B\x05,\x0d End\x05:   Goto \x0dt\x05op / \x0db\x05ottom of text"),
  217.       SYS.ADR( " (\x0DShift\x05) \x0DF\x05, \x0DN\x05, \x0DP\x05:    \x0DF\x05ind string (case sensitive), \x0DN\x05ext, \x0DP\x05revious"),
  218.       SYS.ADR( " \x0dShift \x05+\x0d Fn\x05:         Set textmarker #n to current position"),
  219.       SYS.ADR( " \x0dFn\x05:                 Goto marker #n or set marker #n if it wasn't set yet"),
  220.       SYS.ADR( " \x0dG\x05:                  \x0dG\x05oto line..."),
  221.       SYS.ADR( " \x0dNK 0\x05:               Display info line"),
  222.       SYS.ADR( " \x0dShift \x05+\x0d Alt \x05+\x0d O\x05:    Print text"),
  223.       SYS.ADR( " \x0dW\x05:                  \x0dW\x05rite block between marker #1 and #2 to file or prt"),
  224.       SYS.ADR( " \x0dL\x05:                  \x0dL\x05oad new text"),
  225.       SYS.ADR( " \x0dHELP\x05,\x0d H\x05:            Show commands"),
  226.       SYS.ADR( " \x0dESC\x05,\x0d Q\x05,\x0d X\x05,\x0d NK 5\x05:\x0d    Q\x05uit"),
  227.       SYS.ADR( "© \x131988-94 Fridtjof Siebert & Christian Stiens"),
  228.       SYS.ADR( ""),
  229.       SYS.ADR( "  \x13Please refer to MuchMore.doc for a detailed copyright notice"),
  230.       SYS.ADR( "  This is another product of the Amiga MODULA & OBERON Klub Stuttgart - \x0d\x13AMOK"),
  231.       SYS.ADR( " \x0dC\x05:                  \x0dC\x05opy block between marker #1 and #2 to clipboard"),
  232.       SYS.ADR( " \x0dShift \x05+\x0d Alt \x05+\x0d E\x05:    \x0dE\x05dit text") );
  233.  
  234.  
  235.  
  236. TYPE BusyPointer = ARRAY 36 OF INTEGER;
  237.  
  238. CONST TheBusyPointer = BusyPointer(
  239.   00000U,00000U,
  240.   00400U,007C0U, 00000U,007C0U, 00100U,00380U, 00000U,007E0U,
  241.   007C0U,01FF8U, 01FF0U,03FECU, 03FF8U,07FDEU, 03FF8U,07FBEU,
  242.   07FFCU,0FF7FU, 07EFCU,0FFFFU, 07FFCU,0FFFFU, 03FF8U,07FFEU,
  243.   03FF8U,07FFEU, 01FF0U,03FFCU, 007C0U,01FF8U, 00000U,007E0U,
  244.   00000U,00000U);
  245.  
  246.  
  247. CONST (* RawKey Codes: *)
  248.  
  249.   ESC   = 45H; HELP  = 5FH;
  250.   UP    = 4CH; DOWN  = 4DH;
  251.   SPACE = 40H; BS    = 41H;
  252.   CR    = 44H; ENTER = 43H;
  253.   NK0   = 0FH; NK1   = 1DH; NK2   = 1EH; NK3   = 1FH;
  254.   NK5   = 2EH; NK7   = 3DH; NK8   = 3EH; NK9   = 3FH;
  255.   F1    = 50H; F10   = 59H;
  256.  
  257.  
  258. CONST
  259.   ShowStackSize = 4096;
  260.   BufferSize = 2048;
  261.  
  262.   w = TRUE;
  263.   f = FALSE;
  264.  
  265.   MyIdcmp = LONGSET{I.rawKey,I.mouseButtons,I.closeWindow,I.activeWindow,I.inactiveWindow,I.newSize};
  266.  
  267. (* Control codes: *)
  268.   plain    = 11X;
  269.   italic   = 12X;
  270.   bold     = 13X;
  271.   boldit   = 14X;
  272.   ulineon  = 15X;
  273.   ulineoff = 16X;
  274.  
  275.   Italic = 0;
  276.   Bold   = 1;
  277.   Ulin   = 2;
  278.   Inv    = 3;
  279.  
  280. TYPE
  281.   String    = e.STRING;
  282.   StringPtr = e.STRPTR;
  283.   CharPtr   = UNTRACED POINTER TO CHAR;
  284.   LongPtr   = UNTRACED POINTER TO LONGINT;
  285.  
  286.   TextLinePtr = UNTRACED POINTER TO TextLine;
  287.   TextLine = STRUCT
  288.                prev : TextLinePtr;
  289.                next : TextLinePtr;
  290.                len  : INTEGER;
  291.                size : INTEGER;
  292.                text : String;
  293.              END;
  294.  
  295. CONST
  296.   MaxLen = SIZE(String);
  297.  
  298. TYPE
  299.  
  300.   WBStartupPtr = UNTRACED POINTER TO STRUCT (message : e.Message)
  301.                    process    : d.ProcessId;
  302.                    segment    : e.BPTR;
  303.                    numArgs    : LONGINT;
  304.                    toolWindow : StringPtr;
  305.                    argList : UNTRACED POINTER TO ARRAY 256 OF STRUCT
  306.                                  lock : d.FileLockPtr;
  307.                                  name : StringPtr;
  308.                              END;
  309.                  END;
  310.  
  311.   DiskObjectPtr = UNTRACED POINTER TO STRUCT
  312.                     magic      : INTEGER;
  313.                     version    : INTEGER;
  314.                     gadget     : I.Gadget;
  315.                     type       : SHORTINT;
  316.                     defaultTool: StringPtr;
  317.                     toolTypes  : e.APTR;
  318.                     currentX   : LONGINT;
  319.                     currentY   : LONGINT;
  320.                     drawerData : e.APTR;
  321.                     toolWindow : StringPtr;
  322.                     stackSize  : LONGINT;
  323.                   END;
  324.  
  325.   Args = STRUCT (dummy: d.ArgsStruct)
  326.            b     : LongPtr;
  327.            c     : StringPtr;
  328.            d     : StringPtr;
  329.            e     : StringPtr;
  330.            f     : StringPtr;
  331.            i     : StringPtr;
  332.            o     : StringPtr;
  333.            p     : LongPtr;
  334.            q     : StringPtr;
  335.            s     : LongPtr;
  336.            t     : LongPtr;
  337.            u     : StringPtr;
  338.            x     : LongPtr;
  339.            w     : StringPtr;
  340.            wl    : LongPtr;
  341.            wt    : LongPtr;
  342.            ww    : LongPtr;
  343.            wh    : LongPtr;
  344.            fw    : LongPtr;
  345.            fh    : LongPtr;
  346.            file  : StringPtr;
  347.          END;
  348.  
  349. (*------  Memory:  ------*)
  350.  
  351. CONST ChunkSize = 16384;          (* size of allocated chunks *)
  352.  
  353. TYPE
  354.   MemChunkPtr = UNTRACED POINTER TO MemChunk;  (* chunklist *)
  355.  
  356.   MemChunk = STRUCT
  357.                prev: MemChunkPtr;     (* link *)
  358.                data: ARRAY ChunkSize OF CHAR; (* ChunkSize Bytes of memory *)
  359.              END;
  360.  
  361.  
  362. (*------  Globals  ------*)
  363.  
  364. VAR
  365.   pub            : I.ScreenPtr;        (* default public screen             *)
  366.   Screen         : I.ScreenPtr;        (* MuchMore's Screen                 *)
  367.   Window         : I.WindowPtr;        (* MuchMore's Window                 *)
  368.   rp             : g.RastPortPtr;      (* Screen's RastPort                 *)
  369.   BM             : g.BitMapPtr;        (* Screen's BitMap                   *)
  370.   id             : LONGINT;            (* Display ID                        *)
  371.   catalog        : loc.CatalogPtr;     (* The Catalog                       *)
  372.   MyFile         : d.FileHandlePtr;    (* For loading Textfile              *)
  373.   MyAttr         : g.TextAttr;         (* The selected Font attributes      *)
  374.   MyFont         : g.TextFontPtr;      (* The selected Font                 *)
  375.   OldFont        : g.TextFontPtr;      (* To save old Font                  *)
  376.   FontName       : String;             (* My Font Name or                   *)
  377.   FontSize       : INTEGER;            (* My Font Size                      *)
  378.   FirstLine      : TextLinePtr;        (* the topmost Line                  *)
  379.   TopLine        : TextLinePtr;        (* the topmost Line                  *)
  380.   BottomLine     : TextLinePtr;        (* Last Line displayed on Screen     *)
  381.   LoadLine       : TextLinePtr;        (* currently loaded Line             *)
  382.   LastLine       : TextLinePtr;        (* Last element of LineList          *)
  383.   writeText      : TextLine;           (* temp. Text Line                   *)
  384.   Name,OldName   : String;             (* Text's Name                       *)
  385.   option         : String;             (* CLI Option                        *)
  386.   pubscreenname  : String;
  387.   zoomBox        : ARRAY 4 OF INTEGER;
  388.   editcmd        : String;
  389.   Pens           : String;             (* Screen colors                     *)
  390.   Cols           : ARRAY 4 OF INTEGER; (* Color array for LoadRGB4          *)
  391.   busyPointer    : UNTRACED POINTER TO BusyPointer;
  392.   icon           : DiskObjectPtr;      (* info                              *)
  393.   nameptr        : StringPtr;          (* String Pointer                    *)
  394.   chptr          : CharPtr;            (* Char Pointer                      *)
  395.   PStr           : String;             (* The command for Dos.Execute       *)
  396.   Buffer         : UNTRACED POINTER TO ARRAY BufferSize OF CHAR; (* ReadBuf *)
  397.   RQPos          : LONGINT;            (* Position within ReadBuffer        *)
  398.   RQLen          : LONGINT;            (* Number of CHARs in Buffer         *)
  399.   AnzLines       : LONGINT;            (* Length of Text in Lines           *)
  400.   NumLines       : INTEGER;            (* Number of Lines on Screen         *)
  401.   fontWidth,fontHeight: INTEGER;       (* Font size                         *)
  402.   fontBaseLine   : INTEGER;            (* Font base line                    *)
  403.   spacing        : INTEGER;            (* Extra Line Spacing                *)
  404.   NumColumns     : INTEGER;            (* Number of Columns on Screen       *)
  405.   PageHeight     : INTEGER;            (* fontHeight*NumLines               *)
  406.   i,j            : INTEGER;            (* count                             *)
  407.   left,top       : INTEGER;            (* Dimensions of MMs window          *)
  408.   width,height   : INTEGER;
  409.   initialheight  : INTEGER;
  410.   depth          : INTEGER;            (* Number of planes                  *)
  411.   ci             : INTEGER;            (* Color index                       *)
  412.   scrollmode     : INTEGER;            (* The scrollmode                    *)
  413.   taskpri,oldpri : SHORTINT;           (* Muchmore's Task Priority          *)
  414.   frwidth,frheight:INTEGER;
  415.   MyLock,OldDir  : d.FileLockPtr;      (* To Examine and Load File          *)
  416.   oldcd          : d.FileLockPtr;      (* To save old CD                    *)
  417.   progdir        : d.FileLockPtr;      (* Lock on PROGDIR:                  *)
  418.   clock          : d.FileLockPtr;      (* Lock on C:                        *)
  419.   FileInfo       : d.FileInfoBlockPtr; (* to get File's length              *)
  420.   FileLength,TextLength : LONGINT;     (* Length of File and Displayed Text *)
  421.   ReadLength     : LONGINT;            (* Length of Text while reading      *)
  422.   ScreenPos      : INTEGER;            (* actual position within bitmap     *)
  423.   ShowTask       : e.TaskPtr;          (* the task that displays the text   *)
  424.   ShowStack      : e.APTR;             (* it's stack                        *)
  425.   ShowTaskRunning: BOOLEAN;            (* is Showtask activated?            *)
  426.   win            : BOOLEAN;            (* Is MM running in a window?        *)
  427.   interleaved    : BOOLEAN;            (* Use interleaved Screen?           *)
  428.   zoomed         : BOOLEAN;            (* Is MM iconified ?                 *)
  429.   stdin          : BOOLEAN;            (* Are we reading from STDIN ?       *)
  430.   SignalNewData  : BOOLEAN;            (* Signal when new data is loaded    *)
  431.   SignalAllRead  : BOOLEAN;            (* send signal at end of text        *)
  432.   Done           : BOOLEAN;            (* Quit                              *)
  433.   print          : BOOLEAN;            (* print text?                       *)
  434.   save           : BOOLEAN;            (* save block?                       *)
  435.   copy           : BOOLEAN;            (* copy block to clipboard?          *)
  436.   NewText        : BOOLEAN;            (* load new text                     *)
  437.   Info           : BOOLEAN;            (* is info currently displayed ?     *)
  438.   modeReq        : BOOLEAN;            (* Show Display Mode Requester?      *)
  439.   Scroll         : BOOLEAN;            (* scrolling or waiting?             *)
  440.   Fast           : BOOLEAN;            (* scroll quick?                     *)
  441.   Sync           : BOOLEAN;            (* scroll very quick?                *)
  442.   Decrunched     : BOOLEAN;            (* Is file decrunched?               *)
  443.   Scrollable     : BOOLEAN;            (* is screen able to scroll?         *)
  444.   refresh        : BOOLEAN;            (* Refresh Window?                   *)
  445.   oldstyle       : BOOLEAN;            (* Page Up/Down with soft scroll?    *)
  446.   lace           : BOOLEAN;            (* Is screen interlaced?             *)
  447.   cLocked        : BOOLEAN;            (* Is C: locked ?                    *)
  448.   NewDisp        : BOOLEAN;            (* need to rebuild Display ?         *)
  449.   fastquit       : BOOLEAN;
  450.   ok             : BOOLEAN;
  451.   style          : SHORTSET;           (* Text style                        *)
  452.   mySig          : LONGSET;            (* My Signal Set                     *)
  453.   showSig        : LONGSET;            (* ShowTask's Signal Set             *)
  454.   Me             : d.ProcessPtr;       (* my main task                      *)
  455.   meInt          : LONGINT;            (* for making unique filename        *)
  456.   MyMsgPtr       : I.IntuiMessagePtr;  (* for receiving Messages            *)
  457.   in,out         : d.FileHandlePtr;    (* i/o for TYPE xxx TO PRT:          *)
  458.   mySigBit       : INTEGER;            (* My Signal Bit                     *)
  459.   showSigBit     : INTEGER;            (* ShowTask's Sig Bit                *)
  460.   frame          : INTEGER;            (* Frame Count                       *)
  461.   fg,bg          : INTEGER;            (* Text colors                       *)
  462.   oldfg,oldbg    : INTEGER;            (* Old Text colors                   *)
  463.   tabw           : INTEGER;            (* Tabulator width                   *)
  464.   rd             : d.RDArgsPtr;        (* For ReadArgs                      *)
  465.   args           : Args;               (* My CLI Args                       *)
  466.   ArgPtr         : StringPtr;          (* to get WBArg                      *)
  467.   wbm            : WBStartupPtr;       (* WBenchMessage                     *)
  468.   ri             : g.RasInfoPtr;       (* Screen's ViewPort's RasInfo       *)
  469.   dims           : g.DimensionInfo;    (* Dims for KS2.0                    *)
  470.   disp           : g.DisplayInfo;      (* DisplayInfo for KS2.0             *)
  471.   StrGadget      : I.Gadget;           (* Gadget for Find-Command           *)
  472.   StrInfo        : I.StringInfo;       (* its special info                  *)
  473.   StrExt         : I.StringExtend;     (* its extension                     *)
  474.   asl            : e.LibraryPtr;       (* ASL-librarybase                   *)
  475.   diskFontBase   : e.LibraryPtr;       (* DiskFont-LibraryBase              *)
  476.   xpk            : e.LibraryPtr;       (* XpkMaster-Librarybase             *)
  477.   iconBase       : e.LibraryPtr;       (* Icon-Librarybase                  *)
  478.   Filename       : String;             (* The Filename (without path)       *)
  479.   Dirname        : String;             (* its path                          *)
  480.   Pattern        : ARRAY 80 OF CHAR;   (* The pattern for Filerequester     *)
  481.   TextMarkers    : ARRAY 10 OF TextLinePtr; (* Marked Positions in text     *)
  482.   FindLine       : TextLinePtr;        (* Last found line                   *)
  483.   KeyMap         : ARRAY 50H OF CHAR;  (* console's KeyMap                  *)
  484.   Password       : String;             (* Password for encrypted texts      *)
  485.   conreq         : e.IOStdReqPtr;      (* Console IO-Request                *)
  486.   console        : e.DevicePtr;        (* the console.device                *)
  487.   ievent         : ie.InputEventPtr;   (* InputEvent to convert keycodes    *)
  488.   WriteName      : String;             (* File to write Block               *)
  489.   savefrom,savesize: LONGINT;          (* How much to save?                 *)
  490.   iff            : ip.IFFHandlePtr;    (* IFF Handle for clipboard copy     *)
  491.   buffer         : UNTRACED POINTER TO CHAR; (* Save buffer                 *)
  492.   MemIndex       : INTEGER;            (* index in current Chunk            *)
  493.   CurChunk       : MemChunkPtr;        (* current chunk                     *)
  494.   c              : CHAR;               (* \ used by GetTextLine();          *)
  495.   le             : INTEGER;            (* / global for speed                *)
  496.  
  497.  
  498. (*-------------------------------------------------------------------------*)
  499.  
  500. PROCEDURE OpenDiskFont*{diskFontBase,-30}(VAR textAttr{8}: g.TextAttr): g.TextFontPtr;
  501.  
  502. PROCEDURE GetDiskObject {iconBase,- 78}(name{8}        : ARRAY OF CHAR): DiskObjectPtr;
  503. PROCEDURE FreeDiskObject{iconBase,- 90}(diskobj{8}     : DiskObjectPtr);
  504. PROCEDURE FindToolType  {iconBase,- 96}(toolTypes{8}   : e.APTR;
  505.                                         typeName{9}    : ARRAY OF CHAR): StringPtr;
  506. PROCEDURE MatchToolValue{iconBase,-102}(typeString{8}  : ARRAY OF CHAR;
  507.                                         val{9}         : ARRAY OF CHAR): BOOLEAN;
  508.  
  509. (*-------------------------  ASL Stuff:  ----------------------------------*)
  510.  
  511. CONST
  512.   aslTag  = u.user + 80000H;
  513.  
  514.   taghail   = aslTag + 1;
  515.   window    = aslTag + 2;
  516.   leftEdge  = aslTag + 3;
  517.   topEdge   = aslTag + 4;
  518.   tagWidth  = aslTag + 5;
  519.   tagHeight = aslTag + 6;
  520.   hookFunc  = aslTag + 7;
  521.   file      = aslTag + 8;
  522.   dir       = aslTag + 9;
  523.   pattern   = aslTag + 10;
  524.   funcFlags = aslTag + 20;
  525.   screen    = aslTag + 40;
  526.   sleepWindow=aslTag + 43;
  527.   fiDir     = u.user + 50;
  528.   patGad    = 0;
  529.   fileRequest        = 0;
  530.   screenModeRequest  = 2;
  531.   smPropertyFlags = aslTag+114;
  532.   smPropertyMask  = aslTag+115;
  533.   titleText       = aslTag+1;
  534.   initialDisplayID= aslTag+100;
  535.  
  536. TYPE
  537.   ASLRequesterPtr = UNTRACED POINTER TO ASLRequester;
  538.   ScreenModeRequesterPtr = UNTRACED POINTER TO ScreenModeRequester;
  539.   FileRequesterPtr = UNTRACED POINTER TO FileRequester;
  540.  
  541.   ASLRequester = STRUCT END;
  542.  
  543.   FileRequester = STRUCT (dummy: ASLRequester)
  544.     reserved0 : ARRAY 4 OF e.UBYTE;
  545.     file      : e.STRPTR;
  546.     dir       : e.STRPTR;
  547.     reserved1 : ARRAY 10 OF e.UBYTE;
  548.     leftEdge  : INTEGER;
  549.     topEdge   : INTEGER;
  550.     width     : INTEGER;
  551.     height    : INTEGER;
  552.     reserved2 : ARRAY 2 OF e.UBYTE;
  553.     numArgs   : LONGINT;
  554.     argList   : e.APTR;
  555.     userData  : e.APTR;
  556.     reserved3 : ARRAY 8 OF e.UBYTE;
  557.     pat       : e.STRPTR;
  558.   END;
  559.  
  560.   ScreenModeRequester = STRUCT (dummy: ASLRequester)
  561.     displayID      : LONGINT;
  562.     displayWidth   : LONGINT;
  563.     displayHeight  : LONGINT;
  564.     displayDepth   : INTEGER;
  565.     overscanType   : INTEGER;
  566.     autoScroll     : BOOLEAN;
  567.     pad1           : SHORTINT;
  568.     bitMapWidth    : LONGINT;
  569.     bitMapHeight   : LONGINT;
  570.     leftEdge       : INTEGER;
  571.     topEdge        : INTEGER;
  572.     width          : INTEGER;
  573.     height         : INTEGER;
  574.     infoOpened     : BOOLEAN;
  575.     pad2           : SHORTINT;
  576.     infoLeftEdge   : INTEGER;
  577.     infoTopEdge    : INTEGER;
  578.     infoWidth      : INTEGER;
  579.     infoHeight     : INTEGER;
  580.     userData       : e.APTR;
  581.   END;
  582.  
  583.  
  584. PROCEDURE AllocAslRequestTags{asl,- 48}(reqType{0}: LONGINT; tag1{8}.. : u.Tag): ASLRequesterPtr;
  585. PROCEDURE FreeAslRequest     {asl,- 54}(requester{8}: ASLRequesterPtr);
  586. PROCEDURE AslRequestTags     {asl,- 60}(requester{8}: ASLRequesterPtr; tag1{9}.. : u.Tag): BOOLEAN;
  587.  
  588.  
  589. (*-------------------------------------------------------------------------*)
  590.  
  591. (* $Debug- *)
  592.  
  593. PROCEDURE StuffChar; (* $EntryExitCode- *)
  594. BEGIN
  595.   SYS.INLINE(016C0U, 04E75U)
  596. END StuffChar;
  597.  
  598.  
  599. (*-------------------------------------------------------------------------*)
  600.  
  601.  
  602. PROCEDURE LocStr (num: LONGINT): e.LSTRPTR;
  603. VAR default: e.LSTRPTR;
  604.  
  605. BEGIN
  606.   default := MSGS[num];
  607.   IF loc.base=NIL THEN RETURN default
  608.                   ELSE RETURN loc.GetCatalogStr(catalog,num,default^) END;
  609. END LocStr;
  610.  
  611.  
  612. (*-----------------------------  Requester:  ------------------------------*)
  613.  
  614.  
  615. PROCEDURE Error(Text: ARRAY OF CHAR); (* $CopyArrays- *)
  616. VAR es: I.EasyStruct;
  617.  
  618. BEGIN
  619.   IF ol.wbStarted THEN
  620.     es.structSize   := SIZE(I.EasyStruct);
  621.     es.flags        := LONGSET{};
  622.     es.title        := SYS.ADR(MuchText);
  623.     es.textFormat   := SYS.ADR(Text);
  624.     es.gadgetFormat := LocStr(MSGOK);
  625.     IF I.EasyRequest(NIL,SYS.ADR(es),NIL,NIL)=0 THEN END;
  626.   ELSE
  627.     SYS.SETREG(0,d.Write(d.Output(),Text,str.Length(Text)));
  628.     SYS.SETREG(0,d.Write(d.Output(),"\n",1));
  629.   END;
  630.   HALT(d.fail);
  631. END Error;
  632.  
  633.  
  634. PROCEDURE OutOfMemHandler;
  635. VAR es: I.EasyStruct;
  636.  
  637. BEGIN
  638.   es.structSize   := SIZE(I.EasyStruct);
  639.   es.flags        := LONGSET{};
  640.   es.title        := SYS.ADR(MuchText);
  641.   es.textFormat   := LocStr(MSGOOM);
  642.   es.gadgetFormat := LocStr(MSGRETRYABORT);
  643.   IF I.EasyRequest(NIL,SYS.ADR(es),NIL,NIL)=0 THEN
  644.     HALT(d.fail)
  645.   END;
  646. END OutOfMemHandler;
  647.  
  648.  
  649. (*-------------------------------------------------------------------------*)
  650.  
  651.  
  652. PROCEDURE AllocLine(sz: INTEGER): TextLinePtr;
  653.  
  654. VAR newchunk: MemChunkPtr;
  655.  
  656. BEGIN
  657.   INC(sz,SIZE(TextLine)-MaxLen); IF ODD(sz) THEN INC(sz) END;
  658.   IF MemIndex+sz<=ChunkSize THEN     (* does mem fit into current chunk ? *)
  659.     INC(MemIndex,sz);                (* increment index in current chunk  *)
  660.   ELSE
  661.     NEW(newchunk);                   (* allocate new chunk                *)
  662.     newchunk.prev := CurChunk;       (* link chunk into list              *)
  663.     CurChunk := newchunk;
  664.     MemIndex := sz;
  665.   END;
  666.   RETURN SYS.ADR(CurChunk.data[MemIndex-sz]);
  667. END AllocLine;
  668.  
  669.  
  670. PROCEDURE DisposeLines();
  671.  
  672. VAR chunk: MemChunkPtr;
  673.  
  674. BEGIN
  675.   WHILE CurChunk#NIL DO
  676.     chunk := CurChunk.prev;
  677.     DISPOSE(CurChunk);
  678.     CurChunk := chunk;
  679.   END;
  680.   MemIndex := ChunkSize;
  681. END DisposeLines;
  682.  
  683.  
  684. (*-------------------------------------------------------------------------*)
  685.  
  686.  
  687. PROCEDURE Busy;
  688. BEGIN
  689.   IF Window # NIL THEN
  690.     I.OldModifyIDCMP(Window,MyIdcmp-LONGSET{I.rawKey,I.mouseButtons});
  691.     IF I.base.libNode.version >= 39 THEN
  692.       I.SetWindowPointer(Window,I.waBusyPointer,I.LTRUE,u.done);
  693.     ELSE
  694.       I.SetPointer(Window,busyPointer^,16,16,-6,0);
  695.     END;
  696.   END;
  697. END Busy;
  698.  
  699.  
  700. PROCEDURE UnBusy;
  701. BEGIN
  702.   IF Window # NIL THEN
  703.     IF I.base.libNode.version >= 39 THEN
  704.       I.SetWindowPointer(Window,u.done);
  705.     ELSE
  706.       I.ClearPointer(Window);
  707.     END;
  708.     I.OldModifyIDCMP(Window,MyIdcmp);
  709.   END;
  710. END UnBusy;
  711.  
  712.  
  713. (*------  Scroll:  ------*)
  714.  
  715. PROCEDURE MakeScroll(sync,fast,always: BOOLEAN);
  716. VAR m: INTEGER;
  717.  
  718. BEGIN
  719.   IF Scrollable THEN
  720.     m := 1;
  721.     IF ~always THEN
  722.       IF lace & ~fast THEN m := 2 END;
  723.       IF ~sync THEN INC(m,m*2) END;
  724.     END;
  725.     IF (m=1) OR (frame MOD m=0) THEN
  726.  
  727.       CASE scrollmode OF
  728.  
  729.       | 1: g.ScrollVPort(SYS.ADR(Screen.viewPort));
  730.            g.WaitTOF;
  731.  
  732.       | 2: I.OldMakeScreen(Screen);
  733.            I.OldRethinkDisplay();
  734.  
  735.       (* 3: ScrollRaster *)
  736.  
  737.       | 4: g.WaitTOF;
  738.            g.ScrollVPort(SYS.ADR(Screen.viewPort));
  739.  
  740.       | 5: g.ScrollVPort(SYS.ADR(Screen.viewPort));
  741.            g.WaitBOVP(SYS.ADR(Screen.viewPort));
  742.  
  743.       ELSE (* 0: *)
  744.            I.OldMakeScreen(Screen);
  745.            e.Forbid; SYS.SETREG(0,g.MrgCop(I.ViewAddress())); e.Permit;
  746.            g.WaitTOF;
  747.  
  748.       END;
  749.     END;
  750.     (* $OvflChk- *)
  751.     INC(frame);
  752.     (* $OvflChk= *)
  753.   END;
  754. END MakeScroll;
  755.  
  756.  
  757. (*------  Clear Display:  ------*)
  758.  
  759. PROCEDURE ClearDisplay;
  760. BEGIN
  761.   IF win THEN
  762.     g.SetAPen(rp,0);
  763.     g.RectFill(rp,left,top,left+width-1,top+height-1);
  764.   ELSE
  765.     g.SetRast(rp,0);
  766.   END;
  767.   IF Scrollable THEN
  768.     ri.ryOffset := 0;
  769.     ScreenPos := 0;
  770.     MakeScroll(f,f,w);
  771.   END;
  772. END ClearDisplay;
  773.  
  774. (*-------------------------------------------------------------------------*)
  775.  
  776. (*------  Read one TextLine into a Variable:  ------*)
  777.  
  778.  
  779. PROCEDURE GetTextLine(): TextLinePtr;
  780. (* returns NIL at EOF *)
  781.  
  782. VAR
  783.   l        : TextLinePtr;
  784.   sz,wd,i,j: INTEGER;
  785.   txt      : ARRAY MaxLen+1 OF CHAR;
  786.   num      : ARRAY 10 OF INTEGER;
  787.   newcol   : BOOLEAN;
  788.   oldstyle : SHORTSET;
  789.  
  790.   PROCEDURE GetCh();
  791.   BEGIN
  792.     IF RQPos=RQLen THEN
  793.       RQLen := d.Read(MyFile,Buffer^,BufferSize);
  794.       IF RQLen<0 THEN Error(LocStr(MSGRWERR)^) END;
  795.       RQPos := 0;
  796.     END;
  797.     IF RQLen=0 THEN c := 0X ELSE
  798.       c := Buffer[RQPos]; IF c=0X THEN c:=1X END;
  799.       INC(RQPos); INC(le);
  800.     END;
  801.   END GetCh;
  802.  
  803. BEGIN
  804.   IF RQLen=0 THEN RETURN NIL END;
  805.   sz := 0; wd := 0; le := 0;
  806.   IF Italic IN style THEN IF Bold IN style THEN txt[sz] := boldit ELSE txt[sz] := italic END; INC(sz)
  807.                      ELSE IF Bold IN style THEN txt[sz] := bold; INC(sz) END                      END;
  808.   IF   Ulin IN style     THEN txt[sz] := ulineon; INC(sz) END;
  809.   IF    Inv IN style     THEN txt[sz] := CHR(fg+4*bg+1); INC(sz)
  810.   ELSIF (fg#1) OR (bg#0) THEN txt[sz] := CHR(bg+4*fg+1); INC(sz) END;
  811.   LOOP
  812.     LOOP
  813.       GetCh;
  814.       IF SYS.VAL(CHAR,SYS.VAL(SHORTSET,c)*SHORTSET{0..6})#1BX THEN EXIT END;
  815.       i := -1;
  816.       REPEAT
  817.         GetCh;
  818.         IF (c>=30X) & (c<=39X) THEN
  819.           INC(i); num[i] := 0;
  820.           REPEAT
  821.             num[i] := 10*num[i]+ORD(c)-ORD(30X); GetCh;
  822.           UNTIL (c<30X) OR (c>39X);
  823.         END;
  824.         c := CAP(c);
  825.       UNTIL (c>=3FX(*"?"*)) & (c<=5AX) OR (c=0X) OR (i=9);
  826.       IF c=4DX THEN
  827.         newcol := f; oldstyle := style; j := 0;
  828.         IF i=-1 THEN i:=0; num[0] := 0 END;
  829.         WHILE (i>=j) & (sz<MaxLen-1) DO
  830.           CASE num[j] OF
  831.           0:  style := SHORTSET{}; fg := 1; bg := 0; newcol := w |
  832.           1:  INCL(style,Bold) |
  833.           2:  fg := 2; newcol := w |
  834.           3:  INCL(style,Italic) |
  835.           4:  INCL(style,Ulin) |
  836.           7:  INCL(style,Inv); newcol := w |
  837.           8:  oldfg:=fg; oldbg:=bg; fg:=0; bg:=0; newcol := w |
  838.  
  839.           22: EXCL(style,Bold); fg := 1; newcol := w |
  840.           23: EXCL(style,Italic) |
  841.           24: EXCL(style,Ulin) |
  842.           27: EXCL(style,Inv); newcol := w |
  843.           28: fg:=oldfg; bg:=oldbg; newcol := w |
  844.  
  845.           30..37: fg := (num[j]-30) MOD 4; newcol := w |
  846.           39:     fg := 1; newcol := w |
  847.  
  848.           40..47: bg := (num[j]-40) MOD 4; newcol := w |
  849.           49:     bg := 0; newcol := w |
  850.  
  851.           ELSE END;
  852.           INC(j);
  853.         END;
  854.         IF (oldstyle#style) & (sz<MaxLen) THEN
  855.           IF Italic IN style THEN IF Bold IN style THEN txt[sz] := boldit ELSE txt[sz] := italic END;
  856.                              ELSE IF Bold IN style THEN txt[sz] := bold   ELSE txt[sz] := plain  END;
  857.           END;
  858.           INC(sz);
  859.           IF (Ulin IN style) THEN
  860.             IF ~((Ulin IN oldstyle)) & (sz<MaxLen) THEN
  861.               txt[sz] := ulineon;
  862.               INC(sz);
  863.             END;
  864.           ELSE
  865.             IF (Ulin IN oldstyle) & (sz<MaxLen) THEN
  866.               txt[sz] := ulineoff;
  867.               INC(sz);
  868.             END;
  869.           END;
  870.         END;
  871.         IF newcol & (sz<MaxLen) THEN
  872.           IF Inv IN style THEN txt[sz] := CHR(fg+4*bg+1)
  873.                           ELSE txt[sz] := CHR(bg+4*fg+1) END;
  874.           INC(sz);
  875.         END;
  876.       END;   (* IF c="m" THEN *)
  877.     END;   (* LOOP *)
  878.     CASE c OF
  879.       020X.. 7FX:   txt[sz] := c; INC(sz); INC(wd) |
  880.       0A1X..0FFX:   txt[sz] := c; INC(sz); INC(wd) |
  881.       8X: (* BS *)  IF wd>0 THEN DEC(sz); DEC(wd); END |
  882.       9X: (* TAB *) REPEAT
  883.                       txt[sz] := 20X; INC(sz); INC(wd)
  884.                     UNTIL (sz=MaxLen) OR (wd=NumColumns) OR (sz MOD tabw=0) |
  885.       0A0X:         txt[sz] := 20X; INC(sz); INC(wd) |
  886.       0AX,0X,0CX:   EXIT
  887.     ELSE
  888.     END;
  889.     IF (wd>=NumColumns) OR (sz>=MaxLen) THEN EXIT END;
  890.   END;
  891.   txt[sz] := 0X; INC(sz);
  892.   l := AllocLine(sz);
  893.   l.len := le; l.size:= sz;
  894.   WHILE sz>0 DO DEC(sz); l.text[sz] := txt[sz] END;
  895.   INC(ReadLength,le);
  896.   RETURN l;
  897. END GetTextLine;
  898.  
  899.  
  900. (*------  Write Line to Screen:  ------*)
  901.  
  902.  
  903. PROCEDURE Type(pos: INTEGER; line: TextLinePtr);
  904.  
  905. VAR
  906.   style: SHORTSET;
  907.   front,back: SHORTINT;
  908.   c: CHAR;
  909.   last,i,x,y: INTEGER;
  910.   strPtr: StringPtr;
  911.  
  912. BEGIN
  913.   g.SetDrMd(rp,g.jam2);
  914.   IF Scrollable THEN
  915.     g.SetAPen(rp,0);
  916.     y := pos * fontHeight;
  917.     IF ~refresh THEN g.RectFill(rp,0,y,width-1,y+fontHeight-spacing-1) END;
  918.   END;
  919.   i := 0; x := 0; style := SHORTSET{}; front := 1; back := 0;
  920.   LOOP
  921.     WHILE line.text[i] < " " DO
  922.       c := line.text[i];
  923.       IF c=0X THEN EXIT END;
  924.       CASE c OF
  925.       plain   : style := style - SHORTSET{g.bold,g.italic} |
  926.       italic  : EXCL(style,g.bold); INCL(style,g.italic)   |
  927.       bold    : INCL(style,g.bold); EXCL(style,g.italic)   |
  928.       boldit  : style := style + SHORTSET{g.bold,g.italic} |
  929.       ulineon : INCL(style,g.underlined) |
  930.       ulineoff: EXCL(style,g.underlined) |
  931.       1X..10X : DEC(c);
  932.                 front := SHORT(ORD(c)) DIV 4;
  933.                 back  := SHORT(ORD(c)) MOD 4 |
  934.       ELSE END;
  935.       INC(i);
  936.     END;
  937.     strPtr := SYS.ADR(line.text[i]); last := i;
  938.     REPEAT INC(i) UNTIL line.text[i]<" ";
  939.     SYS.SETREG(0,g.SetSoftStyle(rp,style,-SHORTSET{}));
  940.     g.SetAPen(rp,front);
  941.     g.SetBPen(rp,back);
  942.     g.Move(rp,left+fontWidth*x,top+fontHeight*pos+fontBaseLine);
  943.     g.Text(rp,strPtr^,i-last);
  944.     INC(x,i-last);
  945.   END;
  946. END Type;
  947.  
  948.  
  949. PROCEDURE CopyScrollLine(pos: INTEGER);
  950. (* Kopiert die an pos geschriebene Zeile auf den entsprechenden
  951.  * DoubleBuffer-Bereich
  952.  * ACHTUNG: Darf nur aufgerufen werden, wenn Scrollable TRUE ist!
  953.  *)
  954.  
  955. VAR
  956.   y,z: INTEGER;
  957.  
  958. BEGIN
  959.   y := pos*fontHeight;
  960.   z := PageHeight;
  961.   IF pos >= NumLines THEN z := -z END;
  962.   SYS.SETREG(0,g.BltBitMap(BM, 0,y, BM, 0,y+z, width,fontHeight, 0C0X, SHORTSET{0..7}, NIL));
  963. END CopyScrollLine;
  964.  
  965.  
  966. (*------  Copy String to TextLine:  ------*)
  967.  
  968.  
  969. PROCEDURE CopyToWriteText(String: StringPtr);
  970. VAR i,j : INTEGER;
  971.  
  972. BEGIN
  973.   e.CopyMem(String^,writeText.text,MaxLen-1);
  974.   j := 0;
  975.   FOR i := 0 TO SHORT(str.Length(writeText.text))-1 DO
  976.     IF writeText.text[i] >= " " THEN INC(j) END;
  977.     IF j >= NumColumns THEN
  978.       writeText.text[i] := 0X;
  979.       RETURN
  980.     END;
  981.   END;
  982. END CopyToWriteText;
  983.  
  984.  
  985. (*------  Write String to Screen (at any position):  ------*)
  986.  
  987.  
  988. PROCEDURE TypeTo(VAR text: TextLine; pos: INTEGER);
  989.  
  990. BEGIN
  991.   IF pos < NumLines THEN
  992.     IF Scrollable THEN
  993.       INC(pos,ScreenPos);
  994.       Type(pos,SYS.ADR(text));
  995.       CopyScrollLine(pos);
  996.     ELSE
  997.       Type(pos,SYS.ADR(text));
  998.     END;
  999.   END;
  1000. END TypeTo;
  1001.  
  1002.  
  1003. (*------  Write String to Screen (at any position):  ------*)
  1004.  
  1005.  
  1006. PROCEDURE WriteTo(String: StringPtr; pos: INTEGER);
  1007.  
  1008. BEGIN
  1009.   CopyToWriteText(String);
  1010.   TypeTo(writeText,pos);
  1011. END WriteTo;
  1012.  
  1013.  
  1014. (*------  Write Line at Bottom of Text:  ------*)
  1015.  
  1016.  
  1017. PROCEDURE AddBottomLine(Line: TextLinePtr; Fast: BOOLEAN);
  1018. VAR i,y: INTEGER;
  1019.  
  1020. BEGIN
  1021.   IF ~Scrollable THEN
  1022.     g.SetAPen(rp,0); g.SetBPen(rp,0);
  1023.     IF Fast THEN
  1024.       g.ScrollRaster(rp,0,fontHeight,left,top,left+width-1,top+height-1);
  1025.       IF Sync THEN g.WaitTOF END;
  1026.     ELSE
  1027.       i := fontHeight;
  1028.       REPEAT
  1029.         IF Window.height=initialheight THEN (* Prevent crash under v37 *)
  1030.           g.ScrollRaster(rp,0,1,left,top,left+width-1,top+height-1);
  1031.         END;
  1032.         IF Sync THEN g.WaitTOF END;
  1033.         DEC(i);
  1034.       UNTIL i=0;
  1035.     END;
  1036.     Type(NumLines-1,Line);
  1037.   ELSE
  1038.     Type(ScreenPos+NumLines,Line);
  1039.     y := ScreenPos*fontHeight;
  1040.     IF Fast THEN
  1041.       INC(ri.ryOffset,fontHeight);
  1042.       MakeScroll(Sync,w,f);
  1043.       SYS.SETREG(0,g.BltBitMap(BM, 0,y+PageHeight, BM, 0,y, width,fontHeight, 0C0X, SHORTSET{0..7}, NIL));
  1044.     ELSE
  1045.       i := fontHeight;
  1046.       REPEAT
  1047.         INC(ri.ryOffset);
  1048.         MakeScroll(Sync,f,f);
  1049.         SYS.SETREG(0,g.BltBitMap(BM, 0,y+PageHeight, BM, 0,y, width,1, 0C0X, SHORTSET{0..7}, NIL));
  1050.         INC(y);
  1051.         DEC(i);
  1052.       UNTIL i=0;
  1053.     END;
  1054.     INC(ScreenPos);
  1055.     IF ScreenPos=NumLines THEN
  1056.       ScreenPos := 0;
  1057.       ri.ryOffset := 0;
  1058.     END;
  1059.   END;
  1060. END AddBottomLine;
  1061.  
  1062.  
  1063. (*------  Check whether BottomLine.next is NIL or not:  ------*)
  1064.  
  1065.  
  1066. PROCEDURE TryBottomnext(): BOOLEAN;
  1067. (* returns TRUE if BottomLine.next#NIL END; *)
  1068.  
  1069. BEGIN
  1070.   IF (BottomLine.next=NIL) & (MyFile#NIL) THEN
  1071.     SignalNewData := w;
  1072.     SYS.SETREG(0,e.Wait(showSig));
  1073.     SignalNewData := f;
  1074.   END;
  1075.   RETURN BottomLine.next#NIL;
  1076. END TryBottomnext;
  1077.  
  1078.  
  1079. (*------  Scroll down one Line:  ------*)
  1080.  
  1081.  
  1082. PROCEDURE ScrollDown(Fast: BOOLEAN);
  1083.  
  1084. BEGIN
  1085.   IF TryBottomnext() THEN
  1086.     BottomLine := BottomLine.next;
  1087.     INC(AnzLines);
  1088.     INC(TextLength,BottomLine.len);
  1089.   ELSE RETURN END;
  1090.   IF AnzLines >= NumLines THEN TopLine := TopLine.next END;
  1091.   AddBottomLine(BottomLine,Fast);
  1092. END ScrollDown;
  1093.  
  1094.  
  1095. (*------  Scroll Up one Line:  ------*)
  1096.  
  1097.  
  1098. PROCEDURE ScrUp (Fast: BOOLEAN);
  1099. VAR
  1100.   i,y: INTEGER;
  1101.  
  1102. BEGIN
  1103.   IF ~Scrollable THEN
  1104.     g.SetAPen(rp,0); g.SetBPen(rp,0);
  1105.     IF Fast THEN
  1106.       g.ScrollRaster(rp,0,-fontHeight,left,top,left+width-1,top+height-1);
  1107.       IF Sync THEN g.WaitTOF END;
  1108.     ELSE
  1109.       i := fontHeight;
  1110.       REPEAT
  1111.         IF Window.height=initialheight THEN
  1112.           g.ScrollRaster(rp,0,-1,left,top,left+width-1,top+height-1);
  1113.         END;
  1114.         IF Sync THEN g.WaitTOF END;
  1115.         DEC(i)
  1116.       UNTIL i=0;
  1117.     END;
  1118.     IF TopLine.prev#NIL THEN Type(0,TopLine.prev) ELSE Type(0,FirstLine) END;
  1119.   ELSE
  1120.     IF ScreenPos=0 THEN
  1121.       ri.ryOffset := NumLines*fontHeight;
  1122.       ScreenPos := NumLines;
  1123.     END;
  1124.     DEC(ScreenPos);
  1125.     IF TopLine.prev#NIL THEN Type(ScreenPos,TopLine.prev) ELSE Type(ScreenPos,FirstLine) END;
  1126.     y := ScreenPos*fontHeight;
  1127.     IF Fast THEN
  1128.       DEC(ri.ryOffset,fontHeight);
  1129.       MakeScroll(Sync,w,f);
  1130.       SYS.SETREG(0,g.BltBitMap(BM, 0,y, BM, 0,y+PageHeight, width,fontHeight , 0C0X, SHORTSET{0..7}, NIL));
  1131.     ELSE
  1132.       INC(y,fontHeight);
  1133.       i := fontHeight;
  1134.       REPEAT
  1135.         DEC(ri.ryOffset);
  1136.         MakeScroll(Sync,f,f);
  1137.         DEC(y);
  1138.         SYS.SETREG(0,g.BltBitMap(BM, 0,y, BM, 0,y+PageHeight, width,1, 0C0X, SHORTSET{0..7}, NIL));
  1139.         DEC(i);
  1140.       UNTIL i=0;
  1141.     END;
  1142.   END;
  1143. END ScrUp;
  1144.  
  1145.  
  1146. PROCEDURE ScrollUp(Fast: BOOLEAN);
  1147.  
  1148. BEGIN
  1149.   IF (TopLine.prev#NIL) & (TopLine.prev.prev#NIL) THEN
  1150.     TopLine := TopLine.prev;
  1151.     DEC(TextLength,BottomLine.len);
  1152.     DEC(AnzLines);
  1153.     BottomLine := BottomLine.prev;
  1154.     ScrUp(Fast);
  1155.   END;
  1156. END ScrollUp;
  1157.  
  1158.  
  1159. (*------  Undo last AddBottomLine:  ------*)
  1160.  
  1161.  
  1162. PROCEDURE DelLine(Fast: BOOLEAN);
  1163.  
  1164. BEGIN
  1165.   ScrUp(Fast);
  1166.   Info := f;
  1167. END DelLine;
  1168.  
  1169.  
  1170. (*------  Convert String to Integer:  ------*)
  1171.  
  1172. PROCEDURE StrToInt(str: StringPtr; base: INTEGER): LONGINT;
  1173.  
  1174. VAR
  1175.   i,j: INTEGER;
  1176.   num: LONGINT;
  1177.   ch : CHAR;
  1178.   neg: BOOLEAN;
  1179.  
  1180. BEGIN
  1181.   num := 0; i := 0; neg := f;
  1182.   IF  str^[0] = '-'                   THEN str:=SYS.ADR(str[1]); neg := w END;
  1183.   IF  str^[0] = '$'                   THEN str:=SYS.ADR(str[1]); base:=16 END;
  1184.   IF (str^[0]='0')&(CAP(str^[1])='X') THEN str:=SYS.ADR(str[2]); base:=16 END;
  1185.   LOOP
  1186.     IF i=LEN(str^) THEN EXIT END;
  1187.     ch := CAP(str^[i]);
  1188.     IF ch=0X THEN EXIT END;
  1189.     j := ORD(ch);
  1190.     CASE ch OF
  1191.       "0".."9": DEC(j,ORD('0'))   |
  1192.       "A".."F": DEC(j,ORD('A')-10);
  1193.                 IF base=10 THEN base:=16; i:=-1; j:=0; num:=0 END;
  1194.       ELSE EXIT
  1195.     END;
  1196.     num := num * base + j;
  1197.     INC(i);
  1198.   END;
  1199.   IF neg THEN num := -num END;
  1200.   RETURN num
  1201. END StrToInt;
  1202.  
  1203.  
  1204. (*-------------------------------------------------------------------------*)
  1205.  
  1206.  
  1207. PROCEDURE GetLength(t: TextLinePtr);
  1208.  
  1209. BEGIN
  1210.   TextLength := 0; AnzLines := 0;
  1211.   WHILE t#NIL DO INC(AnzLines); INC(TextLength,t.len); t := t.prev END;
  1212. END GetLength;
  1213.  
  1214.  
  1215. (*-------------------------------------------------------------------------*)
  1216.  
  1217.  
  1218. PROCEDURE NewDisplay;
  1219. (* Zeichnet ab BottomLine neu *)
  1220.  
  1221. VAR
  1222.   i: INTEGER;
  1223.   l: TextLinePtr;
  1224.  
  1225. BEGIN
  1226.   IF ~refresh THEN ClearDisplay END;
  1227.   l := BottomLine.prev;
  1228.   IF l#NIL THEN BottomLine := l END;
  1229.   l := BottomLine;
  1230.   i := NumLines-1;
  1231.   WHILE (i>0) & TryBottomnext() DO
  1232.     BottomLine := BottomLine.next;
  1233.     DEC(i);
  1234.   END;
  1235.   WHILE (i>0) & (l.prev#NIL) DO
  1236.     l := l.prev;
  1237.     DEC(i);
  1238.   END;
  1239.   TopLine := l.next;
  1240.   WHILE i<NumLines DO
  1241.     BottomLine := l;
  1242.     TypeTo(BottomLine^,i);
  1243.     INC(i);
  1244.     l := l.next;
  1245.   END;
  1246.   GetLength(BottomLine);
  1247.   Scroll := f;
  1248.   Info := f;
  1249. END NewDisplay;
  1250.  
  1251.  
  1252. (*-------------------------------------------------------------------------*)
  1253.  
  1254.  
  1255. PROCEDURE GetString(VAR str: ARRAY OF CHAR; int,newdisp,hide: BOOLEAN);
  1256. VAR
  1257.   Win: I.WindowPtr;
  1258.   msg: I.IntuiMessagePtr;
  1259.   class: LONGSET;
  1260.   l,t,w,h: INTEGER;
  1261.   screen: I.ScreenPtr;
  1262.  
  1263. BEGIN
  1264.   MakeScroll(f,f,TRUE);
  1265.   Busy;
  1266.   screen := Screen;
  1267.   w := width DIV 4 * 3;
  1268.   l := (width-w) DIV 2;
  1269.   t := height DIV 2;
  1270.   IF Screen # NIL THEN
  1271.     IF Scrollable THEN INC(t,ri.ryOffset) END;
  1272.     h := Screen.font.ySize+4;
  1273.   ELSE
  1274.     screen := Window.wScreen;
  1275.     INC(l,Window.leftEdge);
  1276.     INC(t,Window.topEdge);
  1277.     h := screen.font.ySize+4;
  1278.   END;
  1279.   StrGadget.leftEdge   := 4;
  1280.   StrGadget.topEdge    := 2;
  1281.   StrGadget.width      := w-8;
  1282.   StrGadget.height     := h-4;
  1283.   StrGadget.activation := {I.stringCenter,I.relVerify};
  1284.   IF int THEN INCL(StrGadget.activation,I.longint) END;
  1285.   StrGadget.flags      := {};
  1286.   StrGadget.gadgetType := I.strGadget;
  1287.   StrGadget.specialInfo:= SYS.ADR(StrInfo);
  1288.   StrInfo.buffer       := SYS.ADR(str);
  1289.   StrInfo.maxChars     := SHORT(LEN(str))-1;
  1290.   StrInfo.extension    := SYS.ADR(StrExt);
  1291.   IF hide THEN INCL(StrGadget.flags,I.stringExtend) END;
  1292.  
  1293.   IF Scrollable THEN Screen.height := Screen.height * 2 END;
  1294.  
  1295.   Win := I.OpenWindowTagsA(NIL,
  1296.                            I.waLeft,  l,
  1297.                            I.waTop,   t,
  1298.                            I.waWidth, w,
  1299.                            I.waHeight,h,
  1300.                            I.waIDCMP, LONGSET{I.gadgetUp,I.activeWindow,I.inactiveWindow},
  1301.                            I.waFlags, LONGSET{I.rmbTrap,I.activate,I.noCareRefresh},
  1302.                            I.waGadgets,SYS.ADR(StrGadget),
  1303.                            I.waCustomScreen,screen,
  1304.                            u.done);
  1305.  
  1306.   IF Scrollable THEN Screen.height := Screen.height DIV 2 END;
  1307.  
  1308.   IF Win # NIL THEN
  1309.     e.WaitPort(Win.userPort);
  1310.     SYS.SETREG(0,I.ActivateGadget(StrGadget,Win,NIL));
  1311.     LOOP
  1312.       e.WaitPort(Win.userPort);
  1313.       msg := e.GetMsg(Win.userPort);
  1314.       IF msg # NIL THEN
  1315.         class := msg.class;
  1316.         e.ReplyMsg(msg);
  1317.         IF (I.gadgetUp IN class) OR (I.inactiveWindow IN class) THEN
  1318.           EXIT
  1319.         END;
  1320.       END;
  1321.     END;
  1322.     I.CloseWindow(Win); Win := NIL;
  1323.   END;
  1324.   UnBusy;
  1325.   IF newdisp & ~win THEN
  1326.     refresh := TRUE; BottomLine := TopLine; NewDisplay; refresh := f;
  1327.   END;
  1328. END GetString;
  1329.  
  1330.  
  1331. (*-------------------------------------------------------------------------*)
  1332.  
  1333.  
  1334. PROCEDURE * ShowProc;
  1335.  
  1336. VAR
  1337.   l           : TextLinePtr;
  1338.   Down        : BOOLEAN;          (* Scroll-Direction                  *)
  1339.   Shift       : BOOLEAN;          (* Shifted Keystroke ?               *)
  1340.   Alt         : BOOLEAN;          (* Altered Keystroke ?               *)
  1341.   wasInfo     : BOOLEAN;          (* was Info line displayed ?         *)
  1342.   found       : BOOLEAN;          (* TRUE, if find was successful      *)
  1343.   chr         : CHAR;             (* converted keycode                 *)
  1344.   caseDelta   : SHORTINT;         (* Case sensitive Search?            *)
  1345.   flen        : INTEGER;          (* length of findstring              *)
  1346.   i,j         : INTEGER;          (* Count                             *)
  1347.   Class       : LONGSET;          (* contains Message.class            *)
  1348.   Code        : INTEGER;          (* contains Message.code             *)
  1349.   Qualifier   : SET;              (* contains Message.qualifier        *)
  1350.   Find,FindStr: ARRAY 80 OF CHAR; (* findstring / capital findstring   *)
  1351.   Goto        : ARRAY 10 OF CHAR; (* string containing goto line #     *)
  1352.   li          : LONGINT;          (* longint value of line to go to    *)
  1353.   HiText      : TextLine;         (* Highlited textline                *)
  1354.   OldHiText   : TextLinePtr;      (* original, un-hilited text         *)
  1355.   skipTab     : ARRAY 256 OF INTEGER;(* for Boyer-Moore Alg.           *)
  1356.  
  1357.  
  1358.   PROCEDURE WaitAllRead();
  1359.  
  1360.   BEGIN
  1361.     IF MyFile # NIL THEN
  1362.       Busy;
  1363.       SignalAllRead := w;
  1364.       SYS.SETREG(0,e.Wait(showSig));
  1365.       SignalAllRead := f;
  1366.       UnBusy;
  1367.     END;
  1368.   END WaitAllRead;
  1369.  
  1370.  
  1371.   PROCEDURE HiLite(at,len: INTEGER);
  1372.   (* Hilites len chars of BottomLine.text starting at position at *)
  1373.  
  1374.   VAR
  1375.     c: INTEGER;
  1376.     col: CHAR;
  1377.  
  1378.   BEGIN
  1379.     OldHiText := BottomLine; HiText := OldHiText^; BottomLine := SYS.ADR(HiText);
  1380.     IF at+len+2<MaxLen THEN
  1381.       c := 0; col := 5X;
  1382.       WHILE c<at DO
  1383.         IF HiText.text[c]<CHR(17) THEN col := HiText.text[c] END;
  1384.         INC(c);
  1385.       END;
  1386.       HiText.text[at] := CHR(17-ORD(col));
  1387.       c := at; INC(len,at);
  1388.       WHILE c<len DO
  1389.         HiText.text[c+1] := OldHiText.text[c];
  1390.         INC(c);
  1391.       END;
  1392.       HiText.text[c+1] := col;
  1393.       REPEAT
  1394.         HiText.text[c+2] := OldHiText.text[c];
  1395.         INC(c);
  1396.       UNTIL HiText.text[c-1]=0X;
  1397.     END;
  1398.     IF HiText.next#NIL THEN HiText.next.prev := SYS.ADR(HiText) END;
  1399.     IF HiText.prev#NIL THEN HiText.prev.next := SYS.ADR(HiText) END;
  1400.   END HiLite;
  1401.  
  1402.  
  1403.   PROCEDURE UnHiLite();
  1404.  
  1405.   BEGIN
  1406.     IF HiText.next#NIL THEN HiText.next.prev := OldHiText END;
  1407.     IF HiText.prev#NIL THEN HiText.prev.next := OldHiText END;
  1408.   END UnHiLite;
  1409.  
  1410.  
  1411.   PROCEDURE CalcSkipTab;  (* Make skip-table for Boyer-Moore Alg. *)
  1412.   VAR i,j: INTEGER;
  1413.  
  1414.   BEGIN
  1415.     FOR i := 0 TO 255 DO skipTab[i] := flen END;
  1416.     i := 0;
  1417.     FOR j := flen-1 TO 0 BY -1 DO
  1418.       IF skipTab[ORD(FindStr[j])] = flen THEN
  1419.         skipTab[ORD(FindStr[j])] := i;
  1420.       END;
  1421.       INC(i);
  1422.     END;
  1423.   END CalcSkipTab;
  1424.  
  1425.  
  1426.   PROCEDURE Search(): BOOLEAN;
  1427.   (* Searches string and hilites it if found. Result is TRUE if string found *)
  1428.  
  1429.   VAR ch: CHAR;
  1430.       i,j,t: INTEGER;
  1431.  
  1432.   BEGIN
  1433.     IF flen > BottomLine.size THEN RETURN f END;
  1434.     i := flen-1;
  1435.     FOR j := flen-1 TO 0 BY -1 DO
  1436.       LOOP
  1437.         ch := BottomLine.text[i];
  1438.         CASE ch OF "a".."z","à".."ö","ø".."þ": DEC(ch,caseDelta) ELSE END;
  1439.         IF ch = FindStr[j] THEN EXIT END;
  1440.         t := skipTab[ORD(ch)];
  1441.         IF flen-j > t THEN INC(i,flen-j) ELSE INC(i,t) END;
  1442.         IF i >= BottomLine.size THEN RETURN f END;
  1443.         j := flen-1;
  1444.       END;
  1445.       DEC(i);
  1446.     END;
  1447.     INC(i); IF i<0 THEN RETURN f END;
  1448.     SYS.SETREG(0,TryBottomnext());
  1449.     FindLine := BottomLine;
  1450.     HiLite(i,flen);
  1451.     found := w; RETURN w;
  1452.   END Search;
  1453.  
  1454.  
  1455.   PROCEDURE ShowInfo(Fast: BOOLEAN);
  1456.   VAR IStr : String;
  1457.       fmt  : e.LSTRPTR;
  1458.       i    : INTEGER;
  1459.       data : STRUCT name : e.STRPTR;
  1460.                     perc : LONGINT;
  1461.                     tlen : LONGINT;
  1462.                     flen : LONGINT;
  1463.                     lins : LONGINT;
  1464.              END;
  1465.   BEGIN
  1466.     data.name := SYS.ADR(OldName);
  1467.     data.tlen := TextLength;
  1468.     data.flen := FileLength;
  1469.     IF data.flen=0 THEN data.flen := ReadLength END;
  1470.     IF data.flen=0 THEN data.flen := 1 END;
  1471.     data.perc := TextLength * 100 DIV data.flen;
  1472.     data.lins := AnzLines-1;
  1473.     fmt := LocStr(MSGINFOFMT);
  1474.     e.OldRawDoFmt(fmt^,SYS.ADR(data),StuffChar,SYS.ADR(IStr));
  1475.     IStr[0] := 7X; IF depth<2 THEN IStr[0] := 2X END;
  1476.     i := SHORT(str.Length(IStr));
  1477.     REPEAT IStr[i] := 20X; INC(i) UNTIL (i>=LEN(IStr)-2) OR (i>=NumColumns+2);
  1478.     IStr[i] := 0X;
  1479.     CopyToWriteText(SYS.ADR(IStr));
  1480.     AddBottomLine(SYS.ADR(writeText),Fast);
  1481.     Info := w;
  1482.     Scroll := f;
  1483.   END ShowInfo;
  1484.  
  1485.  
  1486.   PROCEDURE Help; (* executed when HELP or H is pressed *)
  1487.  
  1488.   CONST
  1489.     num = 25;
  1490.  
  1491.   VAR
  1492.     i,j  : INTEGER;
  1493.     help : ARRAY num OF e.LSTRPTR;
  1494.     fmt  : e.LSTRPTR;
  1495.     data : StringPtr;
  1496.     h1   : String;
  1497.  
  1498.   BEGIN
  1499.     data := SYS.ADR(Version);
  1500.     fmt := LocStr(MSGH1);
  1501.     e.OldRawDoFmt(fmt^,SYS.ADR(data),StuffChar,SYS.ADR(h1));
  1502.     help[ 0] := SYS.ADR(h1);
  1503.     help[ 1] := SYS.ADR("");
  1504.     help[ 2] := LocStr(MSGH2);
  1505.     help[ 3] := LocStr(MSGH3);
  1506.     help[ 4] := LocStr(MSGH4);
  1507.     help[ 5] := LocStr(MSGH5);
  1508.     help[ 6] := LocStr(MSGH6);
  1509.     help[ 7] := LocStr(MSGH7);
  1510.     help[ 8] := LocStr(MSGH8);
  1511.     help[ 9] := LocStr(MSGH9);
  1512.     help[10] := LocStr(MSGH10);
  1513.     help[11] := LocStr(MSGH11);
  1514.     help[12] := LocStr(MSGH12);
  1515.     help[13] := LocStr(MSGH13);
  1516.     help[14] := LocStr(MSGH24);
  1517.     help[15] := LocStr(MSGH14);
  1518.     help[16] := LocStr(MSGH23);
  1519.     help[17] := LocStr(MSGH15);
  1520.     help[18] := LocStr(MSGH16);
  1521.     help[19] := LocStr(MSGH17);
  1522.     help[20] := LocStr(MSGH18);
  1523.     help[21] := SYS.ADR("");
  1524.     help[22] := LocStr(MSGH19);
  1525.     help[23] := LocStr(MSGH21);
  1526.     help[24] := LocStr(MSGH22);
  1527.     ClearDisplay();
  1528.     j := (NumLines - num) DIV 2; IF j<0 THEN j:=0 END;
  1529.     i := 0;
  1530.     WHILE (i<num) & (i+j<NumLines) DO
  1531.       WriteTo(SYS.VAL(StringPtr,help[i]),j+i);
  1532.       INC(i);
  1533.     END;
  1534.     LOOP
  1535.       e.WaitPort(Window.userPort);
  1536.       MyMsgPtr := e.GetMsg(Window.userPort);
  1537.       IF (LONGSET{I.rawKey,I.mouseButtons}*MyMsgPtr.class#LONGSET{}) & (MyMsgPtr.code<128) THEN EXIT END;
  1538.       e.ReplyMsg(MyMsgPtr);
  1539.     END;
  1540.     e.ReplyMsg(MyMsgPtr);
  1541.     BottomLine := TopLine;
  1542.     NewDisplay
  1543.   END Help;
  1544.  
  1545.  
  1546.   PROCEDURE Bottom;  (* executed when END or B is pressed *)
  1547.  
  1548.   BEGIN
  1549.     WaitAllRead;
  1550.     BottomLine := LastLine;
  1551.     NewDisplay
  1552.   END Bottom;
  1553.  
  1554.  
  1555.   PROCEDURE Space(): BOOLEAN;  (* executed if space or LMB is pressed *)
  1556.   (* IF result=w THEN EXIT END *)
  1557.  
  1558.   BEGIN
  1559.     IF (MyFile=NIL) & (BottomLine.next=NIL) THEN        (* End of file? *)
  1560.       IF wasInfo THEN RETURN w END;
  1561.       ShowInfo(Shift);
  1562.     ELSE
  1563.       IF Down THEN
  1564.         Scroll := ~Scroll;
  1565.         IF ~Scroll THEN ShowInfo(Fast) END;
  1566.       ELSE
  1567.         Down := w;
  1568.         Scroll := w;
  1569.       END;
  1570.       Fast := Shift;
  1571.     END;
  1572.     RETURN f;
  1573.   END Space;
  1574.  
  1575.  
  1576.   PROCEDURE BackSpace;  (* executed if backspace or RMB is pressed *)
  1577.  
  1578.   BEGIN
  1579.     Fast := Shift;
  1580.     Scroll := Down OR ~Scroll;
  1581.     Down := f
  1582.   END BackSpace;
  1583.  
  1584.  
  1585. BEGIN
  1586.   (* $IF SmallData *)
  1587.   SYS.SETREG(13,e.AbsExecBase.thisTask.userData);
  1588.   (* $END *)
  1589.  
  1590.   (* $IFNOT ClearVars *)
  1591.   Find[0] := 0X; FindStr[0] := 0X; Goto[0] := 0X;
  1592.   (* $END *)
  1593.  
  1594.   Down := w;
  1595.  
  1596.   SYS.SETREG(0,e.AllocSignal(Window.userPort.sigBit));
  1597.   Window.userPort.sigTask := e.FindTask(NIL);
  1598.  
  1599.   showSigBit := e.AllocSignal(-1);
  1600.   showSig    := LONGSET{showSigBit};
  1601.  
  1602.   e.Signal(Me,mySig);
  1603.   SYS.SETREG(0,e.Wait(showSig));
  1604.  
  1605.   LOOP
  1606.  
  1607.     IF NewDisp THEN NewDisp := f; NewDisplay END;
  1608.  
  1609. (*------  Type Text:  ------*)
  1610.  
  1611.     LOOP
  1612.       IF Scroll THEN
  1613.         IF Down THEN
  1614.           ScrollDown(Fast);
  1615.           Scroll := (MyFile#NIL) OR (BottomLine.next#NIL);
  1616.         ELSE
  1617.           ScrollUp(Fast);
  1618.           Scroll := (TopLine.prev#NIL) & (TopLine.prev.prev#NIL);
  1619.         END;
  1620.       ELSE
  1621.         MakeScroll(f,f,w);
  1622.         e.WaitPort(Window.userPort);
  1623.       END;
  1624.  
  1625.       MyMsgPtr := e.GetMsg(Window.userPort);
  1626.  
  1627.       IF MyMsgPtr # NIL THEN
  1628.         IF ~(I.inactiveWindow IN MyMsgPtr.class) THEN EXIT END;
  1629.         e.ReplyMsg(MyMsgPtr);
  1630.         I.OldModifyIDCMP(Window,MyIdcmp-LONGSET{I.mouseButtons});
  1631.         e.WaitPort(Window.userPort);
  1632.         I.OldModifyIDCMP(Window,MyIdcmp);
  1633.       END;
  1634.  
  1635.     END;
  1636.  
  1637.     Code      := MyMsgPtr.code;
  1638.     Class     := MyMsgPtr.class;
  1639.     Qualifier := MyMsgPtr.qualifier;
  1640.  
  1641.     e.ReplyMsg(MyMsgPtr);
  1642.  
  1643.     Shift := {ie.lShift,ie.rShift,ie.capsLock} * Qualifier # {};
  1644.     Alt   := {ie.lAlt  ,ie.rAlt}               * Qualifier # {};
  1645.     Sync  := ~ (ie.control IN Qualifier);
  1646.  
  1647.     IF ~Sync THEN Shift := w END;
  1648.  
  1649.  
  1650.     IF ((I.rawKey       IN Class) & (Code<80H)) OR
  1651.        ((I.mouseButtons IN Class) & ({ie.leftButton,ie.rightButton}*Qualifier#{}))
  1652.     THEN
  1653.       wasInfo := f;
  1654.       IF Info THEN DelLine(Shift); wasInfo := w; END;
  1655.     END;
  1656.  
  1657.  
  1658.     IF I.mouseButtons IN Class THEN
  1659.  
  1660.       IF    (ie.leftButton IN Qualifier)   & Space()   THEN EXIT
  1661.       ELSIF ie.rightButton IN Qualifier THEN BackSpace END;
  1662.  
  1663.     ELSIF I.closeWindow IN Class THEN
  1664.       EXIT;
  1665.  
  1666.     ELSIF (I.newSize IN Class) THEN
  1667.       Scroll := f;
  1668.       zoomed := w;
  1669.       IF Window.height = initialheight THEN
  1670.         zoomed := f;
  1671.         BottomLine := TopLine;
  1672.         NewDisplay;
  1673.       END;
  1674.  
  1675.     ELSIF (I.rawKey IN Class) & (Code<80H) & ~zoomed THEN
  1676.  
  1677.       CASE Code OF
  1678.  
  1679.       | SPACE: IF Space() THEN EXIT END                     (* Space *)
  1680.  
  1681.       | BS:    BackSpace                                    (* BackSpace *)
  1682.  
  1683.       | DOWN,NK2,NK3:                                       (* Down *)
  1684.  
  1685.           IF (MyFile=NIL) & (BottomLine.next=NIL) THEN
  1686.             I.DisplayBeep(NIL)
  1687.           ELSE
  1688.             IF Shift & (Code # NK3) THEN
  1689.               Scroll := ~Down OR ~Scroll OR ~Fast;
  1690.               Fast := w; Down := w;
  1691.             ELSE
  1692.               IF Alt OR (Code=NK3) THEN
  1693.                 IF oldstyle THEN
  1694.                   i := NumLines-1;
  1695.                   REPEAT
  1696.                     ScrollDown(w);
  1697.                     DEC(i);
  1698.                   UNTIL i=0;
  1699.                 ELSE
  1700.                   IF BottomLine.next#NIL THEN BottomLine := BottomLine.next END;
  1701.                   NewDisplay;
  1702.                 END;
  1703.               ELSE
  1704.                 ScrollDown(w);
  1705.               END;
  1706.               Scroll := f;
  1707.             END;
  1708.           END;
  1709.  
  1710.       | UP,NK8,NK9:                                        (* Up *)
  1711.  
  1712.           IF (TopLine.prev=NIL) OR (TopLine.prev.prev=NIL) THEN
  1713.             I.DisplayBeep(NIL)
  1714.           ELSE
  1715.             IF Shift & (Code # NK9) THEN
  1716.               Scroll := Down OR ~Scroll OR ~Fast;
  1717.               Fast := w; Down := f;
  1718.             ELSE
  1719.               IF Alt OR (Code=NK9) THEN
  1720.                 i := NumLines-1;
  1721.                 IF oldstyle THEN
  1722.                   REPEAT
  1723.                     ScrollUp(w);
  1724.                     DEC(i);
  1725.                   UNTIL i=0;
  1726.                 ELSE
  1727.                   (*IF TopLine.prev#NIL THEN*)
  1728.                   BottomLine := TopLine;
  1729.                   WHILE (i>0) & (BottomLine.prev#NIL) DO
  1730.                     BottomLine := BottomLine.prev;
  1731.                     DEC(i);
  1732.                   END;
  1733.                   NewDisplay;
  1734.                   (*END;*)
  1735.                 END;
  1736.               ELSE
  1737.                 ScrollUp(w);
  1738.               END;
  1739.               Scroll := f;
  1740.             END;
  1741.           END;
  1742.  
  1743.       | CR,ENTER: ScrollDown(f); Scroll := f;              (* CR *)
  1744.  
  1745.       | NK7: BottomLine := FirstLine; NewDisplay           (* Home *)
  1746.  
  1747.       | NK1: Bottom                                        (* End *)
  1748.  
  1749.       | F1..F10:                                           (* F1..F10 *)
  1750.  
  1751.           i := Code-F1;
  1752.           IF ~ Shift & (TextMarkers[i]#NIL) THEN
  1753.             BottomLine := TextMarkers[i];
  1754.             NewDisplay;
  1755.           ELSE
  1756.             TextMarkers[i] := TopLine;
  1757.           END
  1758.  
  1759.       | NK0:  IF ~wasInfo THEN ShowInfo(Shift) END;        (* NK 0 *)
  1760.  
  1761.       | HELP: Help                                         (* Help *)
  1762.  
  1763.       | ESC:  EXIT                                         (* Quit *)
  1764.  
  1765.       | NK5:  IF wasInfo OR fastquit THEN EXIT ELSE ShowInfo(Shift)END; (* safe Quit *)
  1766.  
  1767.       ELSE
  1768.  
  1769.         IF Code<40H THEN         (* examine vanilla keycode: *)
  1770.  
  1771.           chr := KeyMap[Code];
  1772.  
  1773.           CASE chr OF
  1774.  
  1775.           | "t": BottomLine := FirstLine; NewDisplay       (* Home *)
  1776.  
  1777.           | "b": Bottom;                                   (* End *)
  1778.  
  1779.           | "f","n","p":                                   (* Find, Next, Previous *)
  1780.  
  1781.             IF chr="f" THEN
  1782.               caseDelta := 32; IF Shift THEN caseDelta := 0 END;
  1783.               GetString(Find,f,w,f);
  1784.               FindLine := NIL; flen := 0;
  1785.               LOOP
  1786.                 FindStr[flen] := Find[flen];
  1787.                 CASE FindStr[flen] OF
  1788.                   "a".."z","à".."ö","ø".."þ": DEC(FindStr[flen],caseDelta) |
  1789.                   0X: EXIT;
  1790.                 ELSE
  1791.                 END;
  1792.                 INC(flen);
  1793.               END;
  1794.               CalcSkipTab;
  1795.             END;
  1796.             found := f;
  1797.             IF FindStr # "" THEN
  1798.               Busy;
  1799.               i := NumLines;
  1800.               IF FindLine # NIL THEN FindLine := FindLine.next END;
  1801.               WHILE (i>0) & (BottomLine#NIL) & (BottomLine#FindLine) DO
  1802.                 BottomLine := BottomLine.prev; DEC(i);
  1803.               END;
  1804.               IF (BottomLine # FindLine) OR (BottomLine=NIL) THEN
  1805.                 BottomLine := TopLine
  1806.               END;
  1807.               IF chr # "p" THEN                          (* next *)
  1808.                 WHILE (BottomLine # NIL) & ~ Search() DO
  1809.                   SYS.SETREG(0,TryBottomnext());
  1810.                   BottomLine := BottomLine.next;
  1811.                 END;
  1812.               ELSE                                       (* previous *)
  1813.                 IF BottomLine.prev#NIL THEN BottomLine:=BottomLine.prev END;
  1814.                 REPEAT
  1815.                   BottomLine := BottomLine.prev
  1816.                 UNTIL (BottomLine=NIL) OR Search();
  1817.               END;
  1818.               IF BottomLine#NIL THEN
  1819.                 li := NumLines DIV 2;
  1820.                 WHILE (li>0) & (BottomLine.prev#NIL) DO BottomLine := BottomLine.prev; DEC(li) END;
  1821.               END;
  1822.               UnBusy;
  1823.             END;
  1824.  
  1825.             IF ~ found THEN
  1826.               I.DisplayBeep(NIL);
  1827.               BottomLine := TopLine;
  1828.             END;
  1829.             NewDisplay;
  1830.             IF found THEN UnHiLite END;
  1831.  
  1832.           | "w","c":                                       (* write block *)
  1833.             IF (TextMarkers[0]#NIL) & (TextMarkers[1]#NIL) & ~print & ~save THEN
  1834.               savefrom := 0; savesize := 0;
  1835.               l := TextMarkers[0].prev; WHILE l.prev#NIL DO l := l.prev; INC(savefrom,l.len) END;
  1836.               l := TextMarkers[1].prev; WHILE l#NIL DO INC(savesize,l.len); l := l.prev END;
  1837.               l := TextMarkers[1]; i := NumLines; WHILE (i>1) & (l#NIL) DO DEC(i); INC(savesize,LONG(l.len)); l := l.next END;
  1838.               DEC(savesize,savefrom);
  1839.               IF savesize>0 THEN
  1840.                 IF chr="c" THEN copy := w ELSE
  1841.                   GetString(WriteName,f,w,f);
  1842.                   copy := f;
  1843.                 END;
  1844.                 WaitAllRead; save := w; e.Signal(Me,mySig);
  1845.               END
  1846.             END
  1847.  
  1848.           | "o","e":                                       (* Print, Edit *)
  1849.  
  1850.             IF Shift & Alt & ~print & ~save THEN
  1851.               nameptr := SYS.ADR(Name);
  1852.               IF chr="o" THEN
  1853.                 e.OldRawDoFmt('Type "%s" to PRT:',SYS.ADR(nameptr),StuffChar,SYS.ADR(PStr));
  1854.               ELSE
  1855.                 e.OldRawDoFmt(editcmd,SYS.ADR(nameptr),StuffChar,SYS.ADR(PStr));
  1856.               END;
  1857.               WaitAllRead; print := w; e.Signal(Me,mySig);
  1858.             END
  1859.  
  1860.           | "l":                                           (* Load Text *)
  1861.  
  1862.             ClearDisplay;
  1863.             NewText := w; e.Signal(Me,mySig);
  1864.             REPEAT UNTIL (showSigBit IN e.Wait(showSig)) & ~ NewText |
  1865.  
  1866.           | "g":                                           (* goto *)
  1867.  
  1868.             GetString(Goto,w,w,f);
  1869.             li := SHORT(StrInfo.longInt);
  1870.             Busy;
  1871.             BottomLine := FirstLine;
  1872.             WHILE (li >= 0) & TryBottomnext() DO
  1873.               BottomLine := BottomLine.next;
  1874.               DEC(li)
  1875.             END;
  1876.             UnBusy;
  1877.             NewDisplay
  1878.  
  1879.           | "h":     Help                                  (* Help *)
  1880.  
  1881.           | "q","x": IF wasInfo OR fastquit THEN EXIT ELSE ShowInfo(Shift) END; (* safe Quit *)
  1882.  
  1883.           ELSE END;
  1884.  
  1885.         END;   (* IF Code<40H THEN *)
  1886.  
  1887.       END;   (* CASE Code OF *)
  1888.  
  1889.     END;   (* IF I.rawKey IN Class THEN *)
  1890.  
  1891.   END;   (* LOOP *)
  1892.  
  1893.   Done := w;
  1894.   e.Signal(Me,mySig);
  1895.   LOOP SYS.SETREG(0,e.Wait(LONGSET{})) END;
  1896.  
  1897. END ShowProc;
  1898.  
  1899. (* $Debug= *)
  1900.  
  1901.  
  1902. (*--------------------------  File Requester:  ----------------------------*)
  1903.  
  1904.  
  1905. PROCEDURE FileReq(VAR Name: String);
  1906.  
  1907. VAR
  1908.   fr: FileRequesterPtr;
  1909.   pub,scr: I.ScreenPtr;
  1910.   i,j: INTEGER;
  1911.   res: BOOLEAN;
  1912.   screenTag: LONGINT;
  1913.  
  1914. BEGIN
  1915.   j := SHORT(str.Length(Name));
  1916.   WHILE (j>0) & (Name[j]#":") & (Name[j]#"/") DO DEC(j) END;
  1917.   IF j=0 THEN j := -1 END;
  1918.   i := 0;
  1919.   WHILE i<=j DO Dirname[i] := Name[i]; INC(i) END; Dirname[i] := 0X;
  1920.   j := 0;
  1921.   REPEAT Filename[j] := Name[i]; INC(j); INC(i) UNTIL Name[i-1]=0X;
  1922.  
  1923.   IF asl=NIL THEN
  1924.     asl := e.OpenLibrary("asl.library",36);
  1925.     IF asl=NIL THEN Error("Can't open asl.library") END;
  1926.   END;
  1927.  
  1928.   IF (Window # NIL) & (asl.version >= 38) THEN
  1929.     screenTag := screen;
  1930.     scr := Window.wScreen;
  1931.   ELSE
  1932.     screenTag := u.ignore;
  1933.     scr := NIL;
  1934.     pub := I.LockPubScreen(NIL);
  1935.     IF pub # NIL THEN
  1936.       I.ScreenToFront(pub);
  1937.       I.UnlockPubScreen(NIL,pub);
  1938.     END;
  1939.   END;
  1940.  
  1941.   fr := AllocAslRequestTags(fileRequest,
  1942.                             screenTag,scr,
  1943.                             taghail, SYS.ADR(MuchText),
  1944.                             file,    SYS.ADR(Filename),
  1945.                             dir,     SYS.ADR(Dirname),
  1946.                             pattern, SYS.ADR(Pattern),
  1947.                             funcFlags,ASH(1,patGad),
  1948.                             tagWidth, frwidth,
  1949.                             tagHeight,frheight,
  1950.                             u.done);
  1951.   IF fr=NIL THEN Error(LocStr(MSGOOM)^) END;
  1952.  
  1953.   res := AslRequestTags(fr,u.done);
  1954.  
  1955.   IF res THEN
  1956.     COPY(fr.file^,Filename);
  1957.     COPY(fr.dir^,Dirname);
  1958.   END;
  1959.  
  1960.   frwidth  := fr.width;
  1961.   frheight := fr.height;
  1962.   COPY(fr.pat^,Pattern);
  1963.  
  1964.   FreeAslRequest(fr);
  1965.   IF ~res THEN HALT(d.ok) END;
  1966.  
  1967.   Name := Dirname;
  1968.   i := SHORT(str.Length(Name));
  1969.   IF (i>0) THEN
  1970.     CASE Name[i-1] OF "/",":": ELSE
  1971.       Name[i] := "/"; INC(i);
  1972.     END;
  1973.   END;
  1974.   j := 0;
  1975.   LOOP
  1976.     Name[i] := Filename[j];
  1977.     IF (Name[i]=0X) OR (i=255) THEN EXIT END;
  1978.     INC(i);
  1979.     INC(j);
  1980.   END;
  1981.   Name[i] := 0X;
  1982.   IF Window # NIL THEN
  1983.     I.ScreenToFront(Window.wScreen);
  1984.     I.ActivateWindow(Window);
  1985.   END;
  1986. END FileReq;
  1987.  
  1988.  
  1989. (*--------------------------  Decrunch:  ----------------------------*)
  1990.  
  1991.  
  1992. PROCEDURE DirExists(name: ARRAY OF CHAR): BOOLEAN; (* $CopyArrays- *)
  1993. VAR lock: d.FileLockPtr;
  1994.     result: BOOLEAN;
  1995.     oldwp: e.APTR;
  1996. BEGIN
  1997.   result := f;
  1998.   oldwp := Me.windowPtr;
  1999.   Me.windowPtr := -1;
  2000.   lock := d.Lock(name,d.sharedLock);
  2001.   IF lock # NIL THEN
  2002.     result := w;
  2003.     d.UnLock(lock)
  2004.   END;
  2005.   Me.windowPtr := oldwp;
  2006.   RETURN result
  2007. END DirExists;
  2008.  
  2009.  
  2010. PROCEDURE Decrunch;
  2011.  
  2012. CONST
  2013.   tagBase    = u.user + ORD("X")*256 + ORD("P");
  2014.   inName     = tagBase+01H;
  2015.   inFH       = tagBase+02H;
  2016.   outName    = tagBase+10H;
  2017.   password   = tagBase+24H;
  2018.   getError   = tagBase+25H;
  2019.   shortError = tagBase+31H;
  2020.   typePacked = 1;
  2021.   flagsPassword = 0;
  2022.  
  2023. TYPE
  2024.   XpkFib = STRUCT
  2025.     type       : LONGINT;    (* Unpacked, packed, archive? *)
  2026.     uLen       : LONGINT;
  2027.     cLen       : LONGINT;
  2028.     nLen       : LONGINT;
  2029.     uCur       : LONGINT;
  2030.     cCur       : LONGINT;
  2031.     id         : LONGINT;
  2032.     packer     : ARRAY 6 OF CHAR;
  2033.     subVersion : INTEGER;
  2034.     masVersion : INTEGER;
  2035.     flags      : LONGSET;
  2036.     head       : ARRAY 16 OF CHAR;
  2037.     ratio      : LONGINT;
  2038.     reserved   : ARRAY 8 OF LONGINT;
  2039.   END;
  2040.  
  2041. VAR
  2042.   file: d.FileHandlePtr;
  2043.   err: LONGINT;
  2044.   xpkFib: XpkFib;
  2045.   errBuf: ARRAY 81 OF CHAR;
  2046.  
  2047.   PROCEDURE ExamineTags {xpk,-36}(VAR fib{8}  : XpkFib;
  2048.                                   tag1{9}..   : e.APTR): LONGINT;
  2049.   PROCEDURE UnpackTags  {xpk,-48}(tag1{8}..   : e.APTR): LONGINT;
  2050.  
  2051. BEGIN
  2052.   Decrunched := f;
  2053.   OldName := Name;
  2054.   IF stdin THEN RETURN END;
  2055.  
  2056.   IF DirExists("T:") THEN Name := "T:" ELSE Name := "RAM:" END;
  2057.  
  2058.   e.OldRawDoFmt("Decrunched.%lx",SYS.ADR(meInt),StuffChar,SYS.ADR(Name[str.Length(Name)]));
  2059.  
  2060.   IF xpk=NIL THEN xpk := e.OpenLibrary("xpkmaster.library",1) END;
  2061.   IF xpk # NIL THEN
  2062.     err := ExamineTags(xpkFib,inFH,SYS.VAL(LONGINT,MyFile),u.done);
  2063.     IF (err#0) & (err#-20) THEN
  2064.       Error(LocStr(MSGOOM)^)
  2065.     END;
  2066.     IF (err=-20) OR (xpkFib.type#typePacked) THEN
  2067.       Name := OldName;
  2068.       RETURN
  2069.     END;
  2070.     IF flagsPassword IN xpkFib.flags THEN GetString(Password,f,f,w) END;
  2071.     Busy;
  2072.     err := UnpackTags(inFH,       SYS.VAL(LONGINT,MyFile),
  2073.                       outName,    SYS.ADR(Name),
  2074.                       password,   SYS.ADR(Password),
  2075.                       getError,   SYS.ADR(errBuf),
  2076.                       shortError, e.true,
  2077.                       u.done);
  2078.     UnBusy;
  2079.     IF err#0 THEN Error(errBuf) END;
  2080.     file := d.Open(Name,d.oldFile);
  2081.     IF file#NIL THEN
  2082.       Decrunched := w;
  2083.       d.OldClose(MyFile);
  2084.       MyFile := file;
  2085.       RETURN
  2086.     ELSE
  2087.       Error(LocStr(MSGCOF)^);
  2088.     END;
  2089.   END;
  2090.   Name := OldName;
  2091. END Decrunch;
  2092.  
  2093.  
  2094. (*-----------------  Screen Mode Requester:  ------------------------*)
  2095.  
  2096.  
  2097. PROCEDURE ScreenModeReq (VAR displayID : LONGINT): BOOLEAN;
  2098.  
  2099. VAR
  2100.   smReq: ScreenModeRequesterPtr;
  2101.   ok: BOOLEAN;
  2102.   initID: LONGINT;
  2103.  
  2104. BEGIN
  2105.   initID := displayID;
  2106.   IF initID = g.invalidID THEN initID := 0 END;
  2107.  
  2108.   IF asl=NIL THEN
  2109.     asl := e.OpenLibrary("asl.library",36);
  2110.     IF asl=NIL THEN Error("Can't open asl.library") END;
  2111.   END;
  2112.  
  2113.   IF asl.version < 38 THEN Error("asl v38 required") END;
  2114.  
  2115.   smReq := AllocAslRequestTags(screenModeRequest,u.done);
  2116.   IF smReq=NIL THEN RETURN f END;
  2117.  
  2118.   ok := AslRequestTags(smReq,
  2119.                        initialDisplayID , initID,
  2120.                        smPropertyFlags  , LONGSET{g.isWB},
  2121.                        smPropertyMask   , LONGSET{g.isWB},
  2122.                        u.done);
  2123.  
  2124.   IF ok THEN displayID := smReq.displayID END;
  2125.  
  2126.   FreeAslRequest(smReq);
  2127.  
  2128.   RETURN ok;
  2129.  
  2130. END ScreenModeReq;
  2131.  
  2132.  
  2133. (*-------------------------------------------------------------------------*)
  2134.  
  2135.  
  2136. PROCEDURE SavePrefs(save: BOOLEAN);
  2137.  
  2138.   PROCEDURE SavePrefsName(name: StringPtr);
  2139.   VAR file: d.FileHandlePtr;
  2140.       l: LONGINT;
  2141.   BEGIN
  2142.     file := d.Open(name^,d.newFile);
  2143.     IF file # NIL THEN
  2144.       SYS.SETREG(0,d.Write(file,"FORM",4));
  2145.       l := 16;
  2146.       SYS.SETREG(0,d.Write(file,l,4));
  2147.       SYS.SETREG(0,d.Write(file,"MUMO",4));
  2148.       SYS.SETREG(0,d.Write(file,"DPID",4));
  2149.       l := 4;
  2150.       SYS.SETREG(0,d.Write(file,l,4));
  2151.       SYS.SETREG(0,d.Write(file,id,4));
  2152.       d.OldClose(file);
  2153.     END;
  2154.   END SavePrefsName;
  2155.  
  2156. BEGIN
  2157.   SavePrefsName(SYS.ADR("ENV:MuchMore.prefs"));
  2158.   IF save THEN
  2159.     SavePrefsName(SYS.ADR("ENVARC:MuchMore.prefs"))
  2160.   END;
  2161. END SavePrefs;
  2162.  
  2163.  
  2164. (*-------------------------------------------------------------------------*)
  2165.  
  2166.  
  2167. PROCEDURE LoadPrefs;
  2168.  
  2169. VAR file: d.FileHandlePtr;
  2170.     l,i,s: LONGINT;
  2171.     buf: ARRAY 80 OF CHAR;
  2172.     ok: BOOLEAN;
  2173.  
  2174. BEGIN
  2175.   file := NIL;
  2176.   IF DirExists("PROGDIR:") THEN
  2177.     file := d.Open("PROGDIR:MuchMore.prefs",d.oldFile);
  2178.   END;
  2179.   IF (file=NIL) & DirExists("ENV:") THEN
  2180.     file := d.Open("ENV:MuchMore.prefs",d.oldFile);
  2181.   END;
  2182.   IF file # NIL THEN
  2183.     LOOP
  2184.       IF (d.Read(file,i,4) <= 0)        OR
  2185.          (i # SYS.VAL(LONGINT,"FORM"))  OR
  2186.          (d.Read(file,s,4) <= 0)        OR
  2187.          (d.Read(file,i,4) <= 0)        OR
  2188.          (i # SYS.VAL(LONGINT,"MUMO"))    THEN EXIT END;
  2189.       WHILE w DO
  2190.         IF (d.Read(file,i,4) <= 0)      OR
  2191.            (d.Read(file,s,4) <= 0)        THEN EXIT END;
  2192.         IF ODD(s) THEN INC(s) END;
  2193.         IF (s=4) & (i=SYS.VAL(LONGINT,"DPID")) THEN
  2194.           SYS.SETREG(0,d.Read(file,id,4));
  2195.         ELSE
  2196.           IF s < 0 THEN EXIT END;
  2197.           SYS.SETREG(0,d.Seek(file,s,d.current));
  2198.         END;
  2199.       END;
  2200.  
  2201.       EXIT;
  2202.     END;
  2203.     d.OldClose(file);
  2204.   END;
  2205.   IF (d.GetVar("EDITOR",buf,SIZE(buf),LONGSET{})>0) THEN
  2206.     COPY(buf,editcmd);
  2207.   END;
  2208. END LoadPrefs;
  2209.  
  2210.  
  2211. (*------------------------  Get Tooltypes:  --------------------------*)
  2212.  
  2213.  
  2214. PROCEDURE ParseIcon(icon: DiskObjectPtr);
  2215. VAR tt: StringPtr;
  2216.  
  2217. BEGIN
  2218.   IF icon # NIL THEN
  2219.     tt := FindToolType(icon.toolTypes,"PALETTE");    IF (tt # NIL) THEN COPY(tt^,Pens) END;
  2220.     tt := FindToolType(icon.toolTypes,"EXTRASPACE"); IF (tt # NIL) THEN spacing := SHORT(StrToInt(tt,10)) END;
  2221.     tt := FindToolType(icon.toolTypes,"FONT");       IF (tt # NIL) THEN COPY(tt^,FontName) END;
  2222.     tt := FindToolType(icon.toolTypes,"EDITOR");     IF (tt # NIL) THEN COPY(tt^,editcmd) END;
  2223.     tt := FindToolType(icon.toolTypes,"OLDSTYLE");   IF (tt # NIL) THEN oldstyle := ~MatchToolValue(tt^,"FALSE") END;
  2224.     tt := FindToolType(icon.toolTypes,"FASTQUIT");   IF (tt # NIL) THEN fastquit := ~MatchToolValue(tt^,"FALSE") END;
  2225.     tt := FindToolType(icon.toolTypes,"INTERLEAVED");IF (tt # NIL) THEN interleaved := ~MatchToolValue(tt^,"FALSE") END;
  2226.     tt := FindToolType(icon.toolTypes,"PLANES");     IF (tt # NIL) THEN depth := SHORT(StrToInt(tt,10)) END;
  2227.     tt := FindToolType(icon.toolTypes,"TABWIDTH");   IF (tt # NIL) THEN tabw := SHORT(StrToInt(tt,10)) END;
  2228.     tt := FindToolType(icon.toolTypes,"PUBSCREEN");  IF (tt # NIL) THEN COPY(tt^,pubscreenname) END;
  2229.     tt := FindToolType(icon.toolTypes,"TOOLPRI");    IF (tt # NIL) THEN taskpri := SHORT(SHORT(StrToInt(tt,10))) END;
  2230.     tt := FindToolType(icon.toolTypes,"SCROLLMODE"); IF (tt # NIL) THEN scrollmode := SHORT(StrToInt(tt,10)) END;
  2231.     tt := FindToolType(icon.toolTypes,"LEFTEDGE");   IF (tt # NIL) THEN left  := SHORT(StrToInt(tt,10)) END;
  2232.     tt := FindToolType(icon.toolTypes,"TOPEDGE");    IF (tt # NIL) THEN top   := SHORT(StrToInt(tt,10)) END;
  2233.     tt := FindToolType(icon.toolTypes,"WIDTH");      IF (tt # NIL) THEN width := SHORT(StrToInt(tt,10)) END;
  2234.     tt := FindToolType(icon.toolTypes,"HEIGHT");     IF (tt # NIL) THEN height:= SHORT(StrToInt(tt,10)) END;
  2235.     tt := FindToolType(icon.toolTypes,"WINDOW");     IF (tt # NIL) THEN win := (MatchToolValue(tt^,"TRUE")) END;
  2236.     tt := FindToolType(icon.toolTypes,"FRWIDTH");    IF (tt # NIL) THEN frwidth := SHORT(StrToInt(tt,10)) END;
  2237.     tt := FindToolType(icon.toolTypes,"FRHEIGHT");   IF (tt # NIL) THEN frheight := SHORT(StrToInt(tt,10)) END;
  2238.     FreeDiskObject(icon);
  2239.   END;
  2240. END ParseIcon;
  2241.  
  2242.  
  2243. (*------------------------------  MAIN:  ----------------------------------*)
  2244.  
  2245. BEGIN
  2246.  
  2247. (*------  Init:  ------*)
  2248.  
  2249.   mySigBit := -1;
  2250.   Me := SYS.VAL(d.ProcessPtr,ol.Me);
  2251.   meInt := SYS.VAL(LONGINT,Me);
  2252.   OldDir := Me.currentDir;
  2253.   oldpri := Me.task.node.pri; taskpri := oldpri;
  2254.   WriteName := "PRT:";
  2255.   MemIndex := ChunkSize;
  2256.   Sync := w;
  2257.   FontSize := 8;
  2258.   Pattern := "~(#?.(info|backdrop))";
  2259.   editcmd := 'C:Ed';
  2260.   id := g.invalidID;
  2261.   tabw := 8;
  2262.   depth := 2;
  2263.   left   := 0;
  2264.   top    := 0;
  2265.   width  := 640;
  2266.   height := 200;
  2267.   frwidth:= 300;
  2268.   frheight := 200;
  2269.   scrollmode := 1;
  2270.  
  2271.   IF (I.base.libNode.version < 37) OR (g.base.libNode.version < 37) THEN
  2272.     IF I.DisplayAlert(0,"\x00\x64\x14Need OS2 or higher!\o",50) THEN END;
  2273.     HALT(d.fail);
  2274.   END;
  2275.  
  2276.   mySigBit := e.AllocSignal(-1);
  2277.   IF mySigBit<0 THEN HALT(d.fail) END;
  2278.   mySig := LONGSET{mySigBit};
  2279.  
  2280.   iconBase := e.OpenLibrary("icon.library",0);
  2281.  
  2282.   IF loc.base # NIL THEN
  2283.     catalog := loc.OpenCatalog(NIL,"muchmore.catalog",u.end);
  2284.   END;
  2285.  
  2286.   ol.OutOfMemHandler := OutOfMemHandler;
  2287.  
  2288.   INCL(ol.MemReqs,e.public);
  2289.  
  2290.   ol.New(ShowStack,ShowStackSize);
  2291.   NEW(ShowTask);
  2292.   NEW(FileInfo);
  2293.   NEW(ievent);
  2294.   NEW(conreq);
  2295.   NEW(Buffer);
  2296.  
  2297.   INCL(ol.MemReqs,e.chip);
  2298.   NEW(busyPointer);
  2299.   e.CopyMem(TheBusyPointer,busyPointer^,SIZE(busyPointer^));
  2300.   EXCL(ol.MemReqs,e.chip);
  2301.  
  2302. (*------  Setup:  ------*)
  2303.  
  2304.   NEW(FirstLine);
  2305. (*FirstLine.size := 0;
  2306.   FirstLine.text[0] := 0X; *)
  2307.  
  2308. (*------  Start:  ------*)
  2309.  
  2310.   LoadPrefs;
  2311.  
  2312.   IF ol.wbStarted THEN
  2313.  
  2314.     wbm := ol.wbenchMsg;
  2315.     IF iconBase # NIL THEN
  2316.       j := SHORT(wbm.numArgs); IF j>2 THEN j := 2 END;
  2317.       FOR i := 0 TO j-1 DO
  2318.         SYS.SETREG(0,d.CurrentDir(wbm.argList[i].lock));
  2319.         nameptr := wbm.argList[i].name;
  2320.         icon := GetDiskObject(nameptr^);
  2321.         IF icon=NIL THEN
  2322.           IF d.base.lib.version >= 37 THEN
  2323.             SYS.SETREG(0,d.CurrentDir(d.GetProgramDir()));
  2324.             icon := GetDiskObject(nameptr^);
  2325.           END;
  2326.           IF icon=NIL THEN
  2327.             clock := d.Lock("C:",d.sharedLock);
  2328.             SYS.SETREG(0,d.CurrentDir(clock));
  2329.             icon := GetDiskObject(nameptr^);
  2330.           END;
  2331.         END;
  2332.         ParseIcon(icon);
  2333.       END;
  2334.     END; (* IF iconBase#NIL *)
  2335.  
  2336.     IF wbm.numArgs >= 2 THEN
  2337.       ArgPtr := wbm.argList^[1].name; Name := ArgPtr^;
  2338.       SYS.SETREG(0,d.CurrentDir(wbm.argList^[1].lock));
  2339.     ELSE
  2340.       SYS.SETREG(0,d.CurrentDir(wbm.argList^[0].lock));
  2341.       FileReq(Name)
  2342.     END;
  2343.     IF clock # NIL THEN d.UnLock(clock) END;
  2344.  
  2345.   ELSE (* CLI started *)
  2346.  
  2347.     stdin := (Me.cis # Me.cli.standardInput); (* Input redirected? *)
  2348.  
  2349.     IF iconBase # NIL THEN
  2350.       progdir := d.GetProgramDir();
  2351.       IF progdir = NIL THEN
  2352.         progdir := d.Lock("C:",d.sharedLock); cLocked := w;
  2353.       END;
  2354.       oldcd := d.CurrentDir(progdir);
  2355.       IF d.GetProgramName(Name,LEN(Name)) THEN
  2356.         nameptr := SYS.VAL(e.APTR,d.FilePart(Name));
  2357.         icon := GetDiskObject(nameptr^);
  2358.         ParseIcon(icon);
  2359.         Name[0] := 0X;
  2360.       END;
  2361.       oldcd := d.CurrentDir(oldcd);
  2362.       IF cLocked THEN d.UnLock(progdir) END;
  2363.     END;
  2364.  
  2365.     rd := d.ReadArgs("B=PLANES/N/K,C=PALETTE/K,D=DISPMODEREQ/S,E=EDITOR/K,F=FONT/K,I=INTERLEAVED/S,O=OLDSTYLE/S,P=TOOLPRI/N/K,Q=FASTQUIT/S,S=SCROLLMODE/N/K,T=TABWIDTH/N/K,U=PUBSCREEN/K,X=EXTRASPACE/N/K,W=WINDOW/S,WL=LEFTEDGE/N/K,WT=TOPEDGE/N/K,WW=WIDTH/N/K,WH=HEIGHT/N/K,FW=FRWIDTH/N/K,FH=FRHEIGHT/N/K,FILE",args,NIL);
  2366.     IF rd=NIL THEN
  2367.       SYS.SETREG(0,d.PrintFault(d.IoErr(),NIL));
  2368.       HALT(d.warn)
  2369.     END;
  2370.     IF args.b # NIL THEN depth := SHORT(args.b^) END;
  2371.     IF args.c # NIL THEN COPY(args.c^,Pens) END;
  2372.     IF args.d # NIL THEN modeReq := w END;
  2373.     IF args.e # NIL THEN COPY(args.e^,editcmd) END;
  2374.     IF args.f # NIL THEN COPY(args.f^,FontName) END;
  2375.     IF args.i # NIL THEN interleaved := w END;
  2376.     IF args.o # NIL THEN oldstyle := w END;
  2377.     IF args.q # NIL THEN fastquit := w END;
  2378.     IF args.p # NIL THEN taskpri := SHORT(SHORT(args.p^)) END;
  2379.     IF args.s # NIL THEN scrollmode := SHORT(args.s^) END;
  2380.     IF args.t # NIL THEN tabw := SHORT(args.t^) END;
  2381.     IF args.u # NIL THEN COPY(args.u^,pubscreenname) END;
  2382.     IF args.x # NIL THEN spacing := SHORT(args.x^) END;
  2383.     IF args.w # NIL THEN win := w END;
  2384.  
  2385.     IF args.wl # NIL THEN left  := SHORT(args.wl^) END;
  2386.     IF args.wt # NIL THEN top   := SHORT(args.wt^) END;
  2387.     IF args.ww # NIL THEN width := SHORT(args.ww^) END;
  2388.     IF args.wh # NIL THEN height:= SHORT(args.wh^) END;
  2389.  
  2390.     IF args.fw # NIL THEN frwidth := SHORT(args.fw^) END;
  2391.     IF args.fh # NIL THEN frheight:= SHORT(args.fh^) END;
  2392.  
  2393.     IF args.file # NIL THEN COPY(args.file^,Name); stdin := f END;
  2394.     d.FreeArgs(rd); rd := NIL;
  2395.   END;
  2396.  
  2397.   IF pubscreenname # "" THEN
  2398.     win := w;
  2399.   END;
  2400.  
  2401.   IF taskpri # oldpri THEN SYS.SETREG(0,e.SetTaskPri(Me,taskpri)) END;
  2402.  
  2403.   IF tabw < 1 THEN tabw := 1 END;
  2404.  
  2405.   IF depth < 1 THEN depth := 1 END;
  2406.   IF depth > 2 THEN depth := 2 END;
  2407.  
  2408.   IF str.Occurs(editcmd,"%s")<0 THEN str.Append(editcmd,' "%s"') END;
  2409.  
  2410.   IF FontName # "" THEN
  2411.     i := 0;
  2412.     j := SHORT(str.Length(FontName));
  2413.     LOOP
  2414.       IF i >= j THEN EXIT END;
  2415.       IF FontName[i]='/' THEN
  2416.         FontName[i] := 0X;
  2417.         FontSize := SHORT(StrToInt(SYS.ADR(FontName[i+1]),10));
  2418.         j := i;
  2419.         EXIT
  2420.       END;
  2421.       INC(i);
  2422.     END;
  2423.     IF j<LEN(FontName)-6 THEN
  2424.       e.CopyMem(".font",FontName[j],6);
  2425.     END;
  2426.   END;
  2427.  
  2428.   IF Pens # "" THEN
  2429.     ci := 0;
  2430.     chptr := SYS.ADR(Pens);
  2431.     Pens[LEN(Pens)-1] := 0X;
  2432.     LOOP
  2433.       Cols[ci] := SHORT(StrToInt(SYS.VAL(StringPtr,chptr),16));
  2434.       INC(ci); IF ci=4 THEN EXIT END;
  2435.       WHILE (chptr^#0X) & (chptr^#",") DO
  2436.         chptr:=SYS.VAL(e.APTR,SYS.VAL(LONGINT,chptr)+1)
  2437.       END;
  2438.       IF chptr^="," THEN
  2439.         chptr:=SYS.VAL(e.APTR,SYS.VAL(LONGINT,chptr)+1)
  2440.       ELSE
  2441.         EXIT
  2442.       END;
  2443.     END;
  2444.   END;
  2445.  
  2446.   IF FontSize>50 THEN FontSize := 50 END;
  2447.   IF FontSize< 5 THEN FontSize :=  5 END;
  2448.  
  2449.   IF spacing< 0 THEN spacing :=  0 END;
  2450.   IF spacing>20 THEN spacing := 20 END;
  2451.  
  2452.   IF width <150 THEN width  := 150 END;
  2453.   IF height< 70 THEN height :=  70 END;
  2454.  
  2455.   IF modeReq THEN
  2456.     IF ScreenModeReq(id) THEN
  2457.       SavePrefs(w);
  2458.     END;
  2459.   END;
  2460.  
  2461. (*------  Open File:  ------*)
  2462.  
  2463.   IF stdin THEN
  2464.     MyFile := d.Input();
  2465.     Name := "STDIN";
  2466.   ELSE
  2467.     LOOP
  2468.       MyFile := d.Open(Name,d.oldFile);
  2469.       IF MyFile#NIL THEN EXIT END;
  2470.       FileReq(Name)
  2471.     END;
  2472.   END;
  2473.  
  2474. (*------  Open Screen:  ------*)
  2475.  
  2476.   IF ~win THEN
  2477.  
  2478.     LOOP
  2479.   
  2480.       IF id=g.invalidID THEN
  2481.         id := g.defaultMonitorID;
  2482.         pub := I.LockPubScreen(NIL);
  2483.         IF pub # NIL THEN
  2484.           id := g.GetVPModeID(SYS.ADR(pub.viewPort));
  2485.           I.UnlockPubScreen(NIL,pub);
  2486.         END;
  2487.       END;
  2488.   
  2489.       IF g.GetDisplayInfoData(NIL,dims,SIZE(dims),g.dtagDims,id) > 0 THEN
  2490.         width  := dims.txtOScan.maxX - dims.txtOScan.minX + 1;
  2491.         height := dims.txtOScan.maxY - dims.txtOScan.minY + 1;
  2492.   
  2493.         IF g.GetDisplayInfoData(NIL,disp,SIZE(disp),g.dtagDisp,id) > 0 THEN
  2494.           lace := g.isLace IN disp.propertyFlags;
  2495.           Scrollable := (g.isDraggable IN disp.propertyFlags) & (scrollmode # 3);
  2496.           IF Scrollable THEN INC(height,height) END;
  2497.   
  2498.           Screen := I.OpenScreenTagsA(NIL,
  2499.                                      I.saLeft,       0,
  2500.                                      I.saTop,        0,
  2501.                                      I.saWidth,      width,
  2502.                                      I.saHeight,     height,
  2503.                                      I.saDepth,      depth,
  2504.                                      I.saDisplayID,  id,
  2505.                                      I.saInterleaved,SYS.VAL(SHORTINT,interleaved),
  2506.                                      I.saOverscan,   I.oScanText,
  2507.                                      I.saPens,       SYS.ADR("\xFF\xFF"),
  2508.                                      I.saQuiet,      I.LTRUE,
  2509.                                      u.done);
  2510.         END;
  2511.       END;
  2512.   
  2513.       IF Screen # NIL THEN EXIT END;
  2514.   
  2515.       DEC(depth);
  2516.       IF depth=0 THEN Error(LocStr(MSGCOS)^) END;
  2517.     END;
  2518.   
  2519.     rp := SYS.ADR(Screen.rastPort);
  2520.     BM := rp.bitMap;
  2521.     ri := Screen.viewPort.rasInfo;
  2522.  
  2523.     IF ci>0 THEN g.LoadRGB4(SYS.ADR(Screen.viewPort),Cols,ci) END;
  2524.   
  2525.     left := 0;
  2526.     top  := 0;
  2527.     width  := Screen.width;
  2528.     height := Screen.height;
  2529.  
  2530.   END;
  2531.  
  2532. (*------  Open Window:  ------*)
  2533.  
  2534.   IF win THEN
  2535.  
  2536.     IF pubscreenname="" THEN pub := I.LockPubScreen(NIL);
  2537.                         ELSE pub := I.LockPubScreen(pubscreenname) END;
  2538.     IF pub # NIL THEN
  2539.  
  2540.       zoomBox[0] := left;
  2541.       zoomBox[1] := top;
  2542.       zoomBox[2] := 200;
  2543.       zoomBox[3] := pub.barHeight+1;
  2544.  
  2545.       Window := I.OpenWindowTagsA(NIL,
  2546.                                   I.waTitle,    SYS.ADR(MuchText),
  2547.                                   I.waLeft,     left,
  2548.                                   I.waTop,      top,
  2549.                                   I.waWidth,    width,
  2550.                                   I.waHeight,   height,
  2551.                                   I.waPubScreen,pub,
  2552.                                   I.waIDCMP,    MyIdcmp,
  2553.                                   I.waFlags,    LONGSET{I.windowDrag,I.windowClose,I.windowDepth,I.rmbTrap,I.activate,I.noCareRefresh},
  2554.                                   I.waZoom,     SYS.ADR(zoomBox),
  2555.                                   u.done);
  2556.       I.UnlockPubScreen(NIL,pub);
  2557.     END;
  2558.  
  2559.   ELSE
  2560.  
  2561.     Window := I.OpenWindowTagsA(NIL,
  2562.                                 I.waLeft,    0,
  2563.                                 I.waTop,     10,
  2564.                                 I.waWidth,   width,
  2565.                                 I.waHeight,  height-10,
  2566.                                 I.waCustomScreen,Screen,
  2567.                                 I.waIDCMP,   MyIdcmp,
  2568.                                 I.waFlags,   LONGSET{I.rmbTrap,I.activate,I.borderless,I.noCareRefresh,I.simpleRefresh,I.backDrop},
  2569.                                 u.done);
  2570.   END;
  2571.  
  2572.   IF Window=NIL THEN Error(LocStr(MSGCOW)^) END;
  2573.   initialheight := Window.height;
  2574.  
  2575.   IF win THEN
  2576.     rp := Window.rPort;
  2577.     left   := Window.borderLeft; top    := Window.borderTop;
  2578.     width  := Window.gzzWidth;   height := Window.gzzHeight;
  2579.     Scrollable := f;
  2580.  
  2581.     IF depth < rp.bitMap.depth THEN
  2582.       IF g.base.libNode.version >= 39 THEN g.SetMaxPen(rp,ASH(LONG(1),depth)-1)
  2583.                                       ELSE rp.mask := SHORTSET{0..depth-1}   END;
  2584.     END;
  2585.  
  2586.   END;
  2587.  
  2588. (*------  Open Font:  ------*)
  2589.  
  2590.   IF FontName # "" THEN
  2591.     MyAttr.name := SYS.ADR(FontName);
  2592.     MyAttr.ySize := FontSize;
  2593.     diskFontBase := e.OpenLibrary("diskfont.library",0);
  2594.     IF diskFontBase # NIL THEN MyFont := OpenDiskFont(MyAttr) END;
  2595.     IF (MyFont # NIL) & ~(g.proportional IN MyFont.flags) THEN
  2596.       OldFont := rp.font;
  2597.       g.SetFont(rp,MyFont)
  2598.     END;
  2599.   END;
  2600.  
  2601.   LOOP
  2602.     fontWidth  := rp.font.xSize;
  2603.     fontHeight := rp.font.ySize;
  2604.     IF (fontWidth<=80) & (fontHeight<=80) & (fontWidth>=4) & (fontHeight>=4) THEN EXIT END;
  2605.     MyAttr.name := SYS.ADR("topaz.font");
  2606.     MyAttr.ySize := 8;
  2607.     MyFont := g.OpenFont(MyAttr);
  2608.     IF MyFont=NIL THEN HALT(d.fail) END;
  2609.     IF OldFont=NIL THEN OldFont := rp.font END;
  2610.     g.SetFont(rp,MyFont);
  2611.   END;
  2612.   INC(fontHeight,spacing);               (* extra spacing *)
  2613.   fontBaseLine := rp.font.baseline;
  2614.  
  2615.   NumColumns := width DIV fontWidth;
  2616.   IF Scrollable THEN NumLines   := (height DIV 2) DIV fontHeight;
  2617.                 ELSE NumLines   := height DIV fontHeight; END;
  2618.   PageHeight := fontHeight*NumLines;
  2619.   height :=     PageHeight;
  2620.  
  2621.   ClearDisplay;
  2622.  
  2623.   IF Scrollable THEN
  2624.     Screen.height := height;
  2625.     I.OldMakeScreen(Screen);
  2626.     I.OldRethinkDisplay;
  2627.   ELSIF win THEN
  2628.     INC(top,(Window.gzzHeight-height) DIV 2);
  2629.   END;
  2630.  
  2631. (*------  Get KeyMap:  ------*)
  2632.  
  2633.   IF e.OpenDevice("console.device",-1,conreq,LONGSET{})#0 THEN HALT(d.fail) END;
  2634.   console := conreq.device;
  2635.   con.base := console;
  2636. (*ievent.nextEvent := NIL;
  2637.   ievent.qualifier := {};
  2638.   ievent.eventAddress := NIL; *)
  2639.   ievent.class := ie.rawkey;
  2640.  
  2641.   FOR i := 0 TO 3FH DO
  2642.     ievent.code := i;
  2643.     SYS.SETREG(0,con.RawKeyConvert(ievent,KeyMap[i],16,NIL));
  2644.   END;
  2645.  
  2646. (*------  Decrunch:  ------*)
  2647.  
  2648.   Decrunch;
  2649.  
  2650. (*------  Init & Add 2nd Task:  ------*)
  2651.  
  2652.   ShowTask.spLower := ShowStack;
  2653.   ShowTask.spUpper := SYS.VAL(e.APTR,SYS.VAL(LONGINT,ShowStack) + ShowStackSize);
  2654.   ShowTask.spReg   := ShowTask.spUpper;
  2655.   ShowTask.node.type := e.task;
  2656.   ShowTask.node.name := SYS.ADR("muchmore show task");
  2657.   ShowTask.node.pri  := Me.task.node.pri+1;
  2658.   (* $IF SmallData *)
  2659.   ShowTask.userData  := SYS.REG(13);           (* VarBase *)
  2660.   (* $END *)
  2661.  
  2662.   e.Forbid;
  2663.    e.AddTask(ShowTask,ShowProc,NIL);
  2664.    ShowTaskRunning := w;
  2665.   e.Permit;
  2666.  
  2667.   SYS.SETREG(0,e.Wait(mySig));
  2668.  
  2669. (*------  Main Load / Display Loop:  ------*)
  2670.  
  2671.   LOOP
  2672.     fg := 1; bg := 0; oldfg := fg; oldbg := bg; style := SHORTSET{};
  2673.     RQLen := -1; RQPos := -1;
  2674.     AnzLines := 1;
  2675.     LastLine := FirstLine;
  2676.     BottomLine := FirstLine;
  2677.     TopLine    := FirstLine;
  2678.     TextLength := 0;
  2679.     ReadLength := 0;
  2680.     FindLine   := NIL;
  2681.     FOR i := 0 TO 9 DO TextMarkers[i] := NIL END;
  2682.  
  2683.     FileLength := 0;
  2684.  
  2685.     IF ~stdin THEN
  2686.       MyLock := d.Lock(Name,d.sharedLock);
  2687.       IF MyLock # NIL THEN
  2688.         IF d.Examine(MyLock,FileInfo^) THEN FileLength := FileInfo.size END;
  2689.         d.UnLock(MyLock); MyLock := NIL;
  2690.         IF FileLength=0 THEN Error(LocStr(MSGEMPTY)^) END;
  2691.       END;
  2692.     END;
  2693.  
  2694.     (*------  Start displaying & Loading:  ------*)
  2695.  
  2696.     NewDisp := w;
  2697.  
  2698.     e.Signal(ShowTask,showSig);
  2699.  
  2700.     REPEAT
  2701.       LoadLine := GetTextLine();
  2702.       IF LoadLine=NIL THEN
  2703.         IF ~stdin THEN d.OldClose(MyFile) END;
  2704.         MyFile := NIL;
  2705.       ELSE
  2706.         LoadLine.prev := LastLine;
  2707.         LastLine.next := LoadLine;
  2708.         LastLine := LoadLine;
  2709.       END;
  2710.       IF SignalNewData THEN e.Signal(ShowTask,showSig) END;
  2711.     UNTIL (MyFile=NIL) OR Done OR NewText;
  2712.     IF SignalAllRead THEN e.Signal(ShowTask,showSig) END;
  2713.     REPEAT
  2714.       SYS.SETREG(0,e.Wait(mySig));
  2715.       IF print THEN
  2716.         in  := d.Open("NIL:",d.newFile);
  2717.         IF d.SystemTags(PStr,d.sysInput,    SYS.VAL(e.APTR,in),
  2718.                              d.sysOutput,   NIL,
  2719.                              d.sysAsynch,   d.DOSTRUE,
  2720.                              d.sysUserShell,d.DOSTRUE,
  2721.                              u.done)                   = -1 THEN
  2722.           d.OldClose(in);
  2723.         ELSE
  2724.           Decrunched := f; INC(meInt);
  2725.         END;
  2726.         in := NIL;
  2727.         print := f;
  2728.       END;
  2729.       IF save THEN
  2730.         in := d.Open(Name,d.oldFile);
  2731.         IF in=NIL THEN I.DisplayBeep(NIL) ELSE
  2732.           ol.New(buffer,savesize);
  2733.           SYS.SETREG(0,d.Seek(in,savefrom,0));
  2734.           IF d.Read(in,buffer^,savesize) # savesize THEN
  2735.             I.DisplayBeep(NIL);
  2736.             d.OldClose(in); in := NIL;
  2737.           ELSE
  2738.             d.OldClose(in); in := NIL;
  2739.             IF copy THEN
  2740.               iff := NIL;
  2741.               LOOP
  2742.                 IF ip.base=NIL THEN EXIT END;
  2743.                 iff := ip.AllocIFF();
  2744.                 IF iff=NIL THEN EXIT END;
  2745.                 iff.stream := SYS.VAL(LONGINT,ip.OpenClipboard(0));
  2746.                 IF iff.stream=NIL THEN EXIT END;
  2747.                 ip.InitIFFasClip (iff);
  2748.                 IF (ip.OpenIFF  (iff, ip.write) = 0) &
  2749.                    (ip.PushChunk(iff, SYS.VAL(LONGINT,"FTXT"), ip.idFORM, ip.sizeUnknown)=0) &
  2750.                    (ip.PushChunk(iff, 0, SYS.VAL(LONGINT,"CHRS"), ip.sizeUnknown)=0) &
  2751.                    (ip.WriteChunkBytes(iff,buffer^,savesize) = savesize) &
  2752.                    (ip.PopChunk (iff)=0) &
  2753.                    (ip.PopChunk (iff)=0) THEN
  2754.                 END;
  2755.                 EXIT;
  2756.               END;
  2757.               IF iff # NIL THEN
  2758.                 ip.CloseIFF(iff);
  2759.                 IF iff.stream#0 THEN ip.CloseClipboard (SYS.VAL(e.APTR,iff.stream)) END;
  2760.                 ip.FreeIFF (iff);
  2761.               END;
  2762.             ELSE
  2763.               out := d.Open(WriteName,d.oldFile);
  2764.               IF out=NIL THEN
  2765.                 out := d.Open(WriteName,d.newFile);
  2766.               ELSE
  2767.                 SYS.SETREG(0,d.Seek(out,0,d.end));
  2768.               END;
  2769.               IF out=NIL THEN I.DisplayBeep(NIL) ELSE
  2770.                 IF d.Write(out,buffer^,savesize)#savesize THEN I.DisplayBeep(NIL) END;
  2771.                 d.OldClose(out); out := NIL;
  2772.               END;
  2773.             END;
  2774.           END;
  2775.           DISPOSE(buffer);
  2776.         END;
  2777.         save := f;
  2778.       END;
  2779.       IF Done THEN EXIT END;
  2780.     UNTIL NewText;
  2781.     IF MyFile # NIL THEN
  2782.       IF ~stdin THEN d.OldClose(MyFile) END;
  2783.       MyFile := NIL
  2784.     END;
  2785.     IF Decrunched & d.DeleteFile(Name) THEN END;
  2786.     Decrunched := f;
  2787.     DisposeLines();
  2788.     FirstLine.next := NIL; NewText := f;
  2789.     Name := OldName;
  2790.     stdin := FALSE;
  2791.     REPEAT
  2792.       FileReq(Name);
  2793.       MyFile := d.Open(Name,d.oldFile);
  2794.     UNTIL MyFile # NIL;
  2795.     Decrunch;
  2796.   END;   (* LOOP *)
  2797.  
  2798. CLOSE
  2799.  
  2800.   IF OldFont     # NIL THEN g.SetFont(rp,OldFont)            END;
  2801.   IF Window      # NIL THEN Window.userPort.sigTask := Me    END;
  2802.   IF ShowTaskRunning   THEN e.RemTask(ShowTask)              END;
  2803.   IF console     # NIL THEN e.CloseDevice(conreq)            END;
  2804.   IF Window      # NIL THEN I.CloseWindow(Window)            END;
  2805.   IF Screen      # NIL THEN I.OldCloseScreen(Screen)         END;
  2806.   IF MyFont      # NIL THEN g.CloseFont(MyFont)              END;
  2807.   IF (MyFile#NIL) & ~stdin THEN d.OldClose(MyFile)           END;
  2808.   IF in          # NIL THEN d.OldClose(in)                   END;
  2809.   IF out         # NIL THEN d.OldClose(out)                  END;
  2810.   IF Decrunched        THEN SYS.SETREG(0,d.DeleteFile(Name)) END;
  2811.   IF xpk         # NIL THEN e.CloseLibrary(xpk)              END;
  2812.   IF asl         # NIL THEN e.CloseLibrary(asl)              END;
  2813.   IF diskFontBase# NIL THEN e.CloseLibrary(diskFontBase)     END;
  2814.   IF iconBase    # NIL THEN e.CloseLibrary(iconBase)         END;
  2815.   IF mySigBit >= 0     THEN e.FreeSignal(mySigBit)           END;
  2816.   IF catalog     # NIL THEN loc.CloseCatalog(catalog);       END;
  2817.   IF taskpri # oldpri  THEN oldpri := e.SetTaskPri(Me,oldpri)END;
  2818.   OldDir := d.CurrentDir(OldDir);
  2819.  
  2820. END MuchMore.
  2821.  
  2822.